| 6 | turtle.tracer(1, 0) # Make the turtle draw faster. |
| 7 | |
| 8 | def main(): |
| 9 | # Move the turtle to the starting position: |
| 10 | turtle.penup() |
| 11 | turtle.goto(-100, -300) # The starting position is x -100, y -300. |
| 12 | turtle.pendown() |
| 13 | |
| 14 | # (!) Uncomment the following line, and changing 30 to another number: |
| 15 | #turtle.setheading(30) |
| 16 | |
| 17 | # (!) Try changing this pensize to other sizes: |
| 18 | turtle.pensize(3) |
| 19 | # (!) Try changing this line to other colors: |
| 20 | turtle.pencolor('green') |
| 21 | |
| 22 | for sides in range(3, 21): # Draw polygons with 3 to 21 sides. |
| 23 | for i in range(sides): # Draw each of the sides for this polygon. |
| 24 | turtle.forward(100) |
| 25 | turtle.left(360 / sides) |
| 26 | |
| 27 | # Write out the number of sides for the shape: |
| 28 | if i == int(sides / 2.0): |
| 29 | turtle.write(str(sides)) |
| 30 | turtle.update() # Finish drawing the screen. |
| 31 | turtle.exitonclick() # When user clicks on the window, close it. |
| 32 | |
| 33 | |
| 34 | try: |