annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/turtledemo/paint.py @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 #!/usr/bin/env python3
jpayne@68 2 """ turtle-example-suite:
jpayne@68 3
jpayne@68 4 tdemo_paint.py
jpayne@68 5
jpayne@68 6 A simple event-driven paint program
jpayne@68 7
jpayne@68 8 - left mouse button moves turtle
jpayne@68 9 - middle mouse button changes color
jpayne@68 10 - right mouse button toggles between pen up
jpayne@68 11 (no line drawn when the turtle moves) and
jpayne@68 12 pen down (line is drawn). If pen up follows
jpayne@68 13 at least two pen-down moves, the polygon that
jpayne@68 14 includes the starting point is filled.
jpayne@68 15 -------------------------------------------
jpayne@68 16 Play around by clicking into the canvas
jpayne@68 17 using all three mouse buttons.
jpayne@68 18 -------------------------------------------
jpayne@68 19 To exit press STOP button
jpayne@68 20 -------------------------------------------
jpayne@68 21 """
jpayne@68 22 from turtle import *
jpayne@68 23
jpayne@68 24 def switchupdown(x=0, y=0):
jpayne@68 25 if pen()["pendown"]:
jpayne@68 26 end_fill()
jpayne@68 27 up()
jpayne@68 28 else:
jpayne@68 29 down()
jpayne@68 30 begin_fill()
jpayne@68 31
jpayne@68 32 def changecolor(x=0, y=0):
jpayne@68 33 global colors
jpayne@68 34 colors = colors[1:]+colors[:1]
jpayne@68 35 color(colors[0])
jpayne@68 36
jpayne@68 37 def main():
jpayne@68 38 global colors
jpayne@68 39 shape("circle")
jpayne@68 40 resizemode("user")
jpayne@68 41 shapesize(.5)
jpayne@68 42 width(3)
jpayne@68 43 colors=["red", "green", "blue", "yellow"]
jpayne@68 44 color(colors[0])
jpayne@68 45 switchupdown()
jpayne@68 46 onscreenclick(goto,1)
jpayne@68 47 onscreenclick(changecolor,2)
jpayne@68 48 onscreenclick(switchupdown,3)
jpayne@68 49 return "EVENTLOOP"
jpayne@68 50
jpayne@68 51 if __name__ == "__main__":
jpayne@68 52 msg = main()
jpayne@68 53 print(msg)
jpayne@68 54 mainloop()