1""" turtle-example-suite: 2 3 tdemo_wikipedia3.py 4 5This example is 6inspired by the Wikipedia article on turtle 7graphics. (See example wikipedia1 for URLs) 8 9First we create (ne-1) (i.e. 35 in this 10example) copies of our first turtle p. 11Then we let them perform their steps in 12parallel. 13 14Followed by a complete undo(). 15""" 16from turtle import Screen, Turtle, mainloop 17from time import clock, sleep 18 19def 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 36def 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 62if __name__ == '__main__': 63 msg = main() 64 print msg 65 mainloop() 66