Let’s Find the Bottom of the Bag
Make a class to demonstrate a turtle moving around the paper bag:
1: | class Demo: |
- | def __init__(self, f): |
- | self.alex = turtle.Turtle() |
- | self.alex.shape("turtle") |
5: | self.f = f |
- | |
- | def bag(self, points): |
- | line = turtle.Turtle() |
- | line.pen(pencolor='brown', pensize=5) |
10: | line.up() |
- | line.goto(points[0], self.f(points[0])) |
- | line.down() |
- | for x in points: |
- | line.goto(x, self.f(x)) |
15: | line.hideturtle() |
- | |
- | def start(self, x): |
- | self.alex.hideturtle() |
- | self.alex.up() |
20: | self.alex.goto(x, self.f(x)) |
- | self.alex.down() |
- | self.alex.showturtle() |
- | self.alex.pen(pencolor='black', pensize=10) |
- | self.alex.speed(1) |
25: | |
- | def move(self, x, y, jump=False): ... |
Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.