ยปCore Development>Code coverage>Lib/turtledemo/round_dance.py

Python code coverage for Lib/turtledemo/round_dance.py

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