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

Python code coverage for Lib/turtledemo/wikipedia.py

#countcontent
1n/a""" turtle-example-suite:
2n/a
3n/a tdemo_wikipedia3.py
4n/a
5n/aThis example is
6n/ainspired by the Wikipedia article on turtle
7n/agraphics. (See example wikipedia1 for URLs)
8n/a
9n/aFirst we create (ne-1) (i.e. 35 in this
10n/aexample) copies of our first turtle p.
11n/aThen we let them perform their steps in
12n/aparallel.
13n/a
14n/aFollowed by a complete undo().
15n/a"""
16n/afrom turtle import Screen, Turtle, mainloop
17n/afrom time import clock, sleep
18n/a
19n/adef mn_eck(p, ne,sz):
20n/a turtlelist = [p]
21n/a #create ne-1 additional turtles
22n/a for i in range(1,ne):
23n/a q = p.clone()
24n/a q.rt(360.0/ne)
25n/a turtlelist.append(q)
26n/a p = q
27n/a for i in range(ne):
28n/a c = abs(ne/2.0-i)/(ne*.7)
29n/a # let those ne turtles make a step
30n/a # in parallel:
31n/a for t in turtlelist:
32n/a t.rt(360./ne)
33n/a t.pencolor(1-c,0,c)
34n/a t.fd(sz)
35n/a
36n/adef main():
37n/a s = Screen()
38n/a s.bgcolor("black")
39n/a p=Turtle()
40n/a p.speed(0)
41n/a p.hideturtle()
42n/a p.pencolor("red")
43n/a p.pensize(3)
44n/a
45n/a s.tracer(36,0)
46n/a
47n/a at = clock()
48n/a mn_eck(p, 36, 19)
49n/a et = clock()
50n/a z1 = et-at
51n/a
52n/a sleep(1)
53n/a
54n/a at = clock()
55n/a while any([t.undobufferentries() for t in s.turtles()]):
56n/a for t in s.turtles():
57n/a t.undo()
58n/a et = clock()
59n/a return "runtime: %.3f sec" % (z1+et-at)
60n/a
61n/a
62n/aif __name__ == '__main__':
63n/a msg = main()
64n/a print(msg)
65n/a mainloop()