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