January 2019
Intermediate to advanced
236 pages
5h 41m
English
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): ... |
Read now
Unlock full access