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