Optional Exercise: Symmetry with Turtles

Make a mirror-image drawing program with Turtle graphics.

Start with a basic click handler function:

# Use the usual documentation header here.

screen = turtle.Screen()
pen = turtle.Turtle()
pen.speed('fastest')

def handle_click(x, y):
    """Handle a click at (x, y) by moving the turtle there."""
    print(x, y)
    # TODO


def handle_clear():
    """Clear the screen and reset the turtle(s)."""
    # TODO


screen.onclick(handle_click)
screen.onkey(handle_clear, "c")
screen.listen() # handle keypresses
screen.mainloop()

Then, do the following:

  1. Finish the click handler so that the turtle moves to the clicked location.
  2. Add a second turtle with a different color.
  3. Make the second turtle mirror the first one. For example, you might make the second turtle’s x-coordinate be the negative of the first turtle’s x-coordinate.
  4. Make a function that draws a shape (e.g., a square or circle) at the current turtle location. Call this function from the click handler for both turtles.
  5. Clear the screen and reset the turtles when the user presses the “c” key.