Last change
on this file was 2, checked in by Yuri Dario, 15 years ago |
Initial import for vendor code.
|
-
Property svn:eol-style
set to
native
|
File size:
1.3 KB
|
Line | |
---|
1 | """ turtle-example-suite:
|
---|
2 |
|
---|
3 | tdemo_wikipedia3.py
|
---|
4 |
|
---|
5 | This example is
|
---|
6 | inspired by the Wikipedia article on turtle
|
---|
7 | graphics. (See example wikipedia1 for URLs)
|
---|
8 |
|
---|
9 | First we create (ne-1) (i.e. 35 in this
|
---|
10 | example) copies of our first turtle p.
|
---|
11 | Then we let them perform their steps in
|
---|
12 | parallel.
|
---|
13 |
|
---|
14 | Followed by a complete undo().
|
---|
15 | """
|
---|
16 | from turtle import Screen, Turtle, mainloop
|
---|
17 | from time import clock, sleep
|
---|
18 |
|
---|
19 | def mn_eck(p, ne,sz):
|
---|
20 | turtlelist = [p]
|
---|
21 | #create ne-1 additional turtles
|
---|
22 | for i in range(1,ne):
|
---|
23 | q = p.clone()
|
---|
24 | q.rt(360.0/ne)
|
---|
25 | turtlelist.append(q)
|
---|
26 | p = q
|
---|
27 | for i in range(ne):
|
---|
28 | c = abs(ne/2.0-i)/(ne*.7)
|
---|
29 | # let those ne turtles make a step
|
---|
30 | # in parallel:
|
---|
31 | for t in turtlelist:
|
---|
32 | t.rt(360./ne)
|
---|
33 | t.pencolor(1-c,0,c)
|
---|
34 | t.fd(sz)
|
---|
35 |
|
---|
36 | def main():
|
---|
37 | s = Screen()
|
---|
38 | s.bgcolor("black")
|
---|
39 | p=Turtle()
|
---|
40 | p.speed(0)
|
---|
41 | p.hideturtle()
|
---|
42 | p.pencolor("red")
|
---|
43 | p.pensize(3)
|
---|
44 |
|
---|
45 | s.tracer(36,0)
|
---|
46 |
|
---|
47 | at = clock()
|
---|
48 | mn_eck(p, 36, 19)
|
---|
49 | et = clock()
|
---|
50 | z1 = et-at
|
---|
51 |
|
---|
52 | sleep(1)
|
---|
53 |
|
---|
54 | at = clock()
|
---|
55 | while any([t.undobufferentries() for t in s.turtles()]):
|
---|
56 | for t in s.turtles():
|
---|
57 | t.undo()
|
---|
58 | et = clock()
|
---|
59 | return "Laufzeit: %.3f sec" % (z1+et-at)
|
---|
60 |
|
---|
61 |
|
---|
62 | if __name__ == '__main__':
|
---|
63 | msg = main()
|
---|
64 | print msg
|
---|
65 | mainloop()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.