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