Debian Codegraph @

Lib/turtledemo/round_dance.py

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