/Demo/turtle/tdemo_paint.py

http://unladen-swallow.googlecode.com/ · Python · 50 lines · 29 code · 4 blank · 17 comment · 3 complexity · ac0f14b28e948260dc5241ee9f173c22 MD5 · raw file

  1. #!/usr/bin/python
  2. """ turtle-example-suite:
  3. tdemo_paint.py
  4. A simple eventdriven paint program
  5. - use left mouse button to move turtle
  6. - middle mouse button to change color
  7. - right mouse button do turn filling on/off
  8. -------------------------------------------
  9. Play around by clicking into the canvas
  10. using all three mouse buttons.
  11. -------------------------------------------
  12. To exit press STOP button
  13. -------------------------------------------
  14. """
  15. from turtle import *
  16. def switchupdown(x=0, y=0):
  17. if pen()["pendown"]:
  18. end_fill()
  19. up()
  20. else:
  21. down()
  22. begin_fill()
  23. def changecolor(x=0, y=0):
  24. global colors
  25. colors = colors[1:]+colors[:1]
  26. color(colors[0])
  27. def main():
  28. global colors
  29. shape("circle")
  30. resizemode("user")
  31. shapesize(.5)
  32. width(3)
  33. colors=["red", "green", "blue", "yellow"]
  34. color(colors[0])
  35. switchupdown()
  36. onscreenclick(goto,1)
  37. onscreenclick(changecolor,2)
  38. onscreenclick(switchupdown,3)
  39. return "EVENTLOOP"
  40. if __name__ == "__main__":
  41. msg = main()
  42. print msg
  43. mainloop()