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:
- Finish the click handler so that the turtle moves to the clicked location.
- Add a second turtle with a different color.
- 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.
- 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.
- Clear the screen and reset the turtles when the user presses the “c” key.