Mercurial > repos > rliterman > csp2
annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/turtledemo/round_dance.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 """ turtle-example-suite: |
jpayne@69 | 2 |
jpayne@69 | 3 tdemo_round_dance.py |
jpayne@69 | 4 |
jpayne@69 | 5 (Needs version 1.1 of the turtle module that |
jpayne@69 | 6 comes with Python 3.1) |
jpayne@69 | 7 |
jpayne@69 | 8 Dancing turtles have a compound shape |
jpayne@69 | 9 consisting of a series of triangles of |
jpayne@69 | 10 decreasing size. |
jpayne@69 | 11 |
jpayne@69 | 12 Turtles march along a circle while rotating |
jpayne@69 | 13 pairwise in opposite direction, with one |
jpayne@69 | 14 exception. Does that breaking of symmetry |
jpayne@69 | 15 enhance the attractiveness of the example? |
jpayne@69 | 16 |
jpayne@69 | 17 Press any key to stop the animation. |
jpayne@69 | 18 |
jpayne@69 | 19 Technically: demonstrates use of compound |
jpayne@69 | 20 shapes, transformation of shapes as well as |
jpayne@69 | 21 cloning turtles. The animation is |
jpayne@69 | 22 controlled through update(). |
jpayne@69 | 23 """ |
jpayne@69 | 24 |
jpayne@69 | 25 from turtle import * |
jpayne@69 | 26 |
jpayne@69 | 27 def stop(): |
jpayne@69 | 28 global running |
jpayne@69 | 29 running = False |
jpayne@69 | 30 |
jpayne@69 | 31 def main(): |
jpayne@69 | 32 global running |
jpayne@69 | 33 clearscreen() |
jpayne@69 | 34 bgcolor("gray10") |
jpayne@69 | 35 tracer(False) |
jpayne@69 | 36 shape("triangle") |
jpayne@69 | 37 f = 0.793402 |
jpayne@69 | 38 phi = 9.064678 |
jpayne@69 | 39 s = 5 |
jpayne@69 | 40 c = 1 |
jpayne@69 | 41 # create compound shape |
jpayne@69 | 42 sh = Shape("compound") |
jpayne@69 | 43 for i in range(10): |
jpayne@69 | 44 shapesize(s) |
jpayne@69 | 45 p =get_shapepoly() |
jpayne@69 | 46 s *= f |
jpayne@69 | 47 c *= f |
jpayne@69 | 48 tilt(-phi) |
jpayne@69 | 49 sh.addcomponent(p, (c, 0.25, 1-c), "black") |
jpayne@69 | 50 register_shape("multitri", sh) |
jpayne@69 | 51 # create dancers |
jpayne@69 | 52 shapesize(1) |
jpayne@69 | 53 shape("multitri") |
jpayne@69 | 54 pu() |
jpayne@69 | 55 setpos(0, -200) |
jpayne@69 | 56 dancers = [] |
jpayne@69 | 57 for i in range(180): |
jpayne@69 | 58 fd(7) |
jpayne@69 | 59 tilt(-4) |
jpayne@69 | 60 lt(2) |
jpayne@69 | 61 update() |
jpayne@69 | 62 if i % 12 == 0: |
jpayne@69 | 63 dancers.append(clone()) |
jpayne@69 | 64 home() |
jpayne@69 | 65 # dance |
jpayne@69 | 66 running = True |
jpayne@69 | 67 onkeypress(stop) |
jpayne@69 | 68 listen() |
jpayne@69 | 69 cs = 1 |
jpayne@69 | 70 while running: |
jpayne@69 | 71 ta = -4 |
jpayne@69 | 72 for dancer in dancers: |
jpayne@69 | 73 dancer.fd(7) |
jpayne@69 | 74 dancer.lt(2) |
jpayne@69 | 75 dancer.tilt(ta) |
jpayne@69 | 76 ta = -4 if ta > 0 else 2 |
jpayne@69 | 77 if cs < 180: |
jpayne@69 | 78 right(4) |
jpayne@69 | 79 shapesize(cs) |
jpayne@69 | 80 cs *= 1.005 |
jpayne@69 | 81 update() |
jpayne@69 | 82 return "DONE!" |
jpayne@69 | 83 |
jpayne@69 | 84 if __name__=='__main__': |
jpayne@69 | 85 print(main()) |
jpayne@69 | 86 mainloop() |