jpayne@68: """ turtle-example-suite: jpayne@68: jpayne@68: tdemo_wikipedia3.py jpayne@68: jpayne@68: This example is jpayne@68: inspired by the Wikipedia article on turtle jpayne@68: graphics. (See example wikipedia1 for URLs) jpayne@68: jpayne@68: First we create (ne-1) (i.e. 35 in this jpayne@68: example) copies of our first turtle p. jpayne@68: Then we let them perform their steps in jpayne@68: parallel. jpayne@68: jpayne@68: Followed by a complete undo(). jpayne@68: """ jpayne@68: from turtle import Screen, Turtle, mainloop jpayne@68: from time import perf_counter as clock, sleep jpayne@68: jpayne@68: def mn_eck(p, ne,sz): jpayne@68: turtlelist = [p] jpayne@68: #create ne-1 additional turtles jpayne@68: for i in range(1,ne): jpayne@68: q = p.clone() jpayne@68: q.rt(360.0/ne) jpayne@68: turtlelist.append(q) jpayne@68: p = q jpayne@68: for i in range(ne): jpayne@68: c = abs(ne/2.0-i)/(ne*.7) jpayne@68: # let those ne turtles make a step jpayne@68: # in parallel: jpayne@68: for t in turtlelist: jpayne@68: t.rt(360./ne) jpayne@68: t.pencolor(1-c,0,c) jpayne@68: t.fd(sz) jpayne@68: jpayne@68: def main(): jpayne@68: s = Screen() jpayne@68: s.bgcolor("black") jpayne@68: p=Turtle() jpayne@68: p.speed(0) jpayne@68: p.hideturtle() jpayne@68: p.pencolor("red") jpayne@68: p.pensize(3) jpayne@68: jpayne@68: s.tracer(36,0) jpayne@68: jpayne@68: at = clock() jpayne@68: mn_eck(p, 36, 19) jpayne@68: et = clock() jpayne@68: z1 = et-at jpayne@68: jpayne@68: sleep(1) jpayne@68: jpayne@68: at = clock() jpayne@68: while any(t.undobufferentries() for t in s.turtles()): jpayne@68: for t in s.turtles(): jpayne@68: t.undo() jpayne@68: et = clock() jpayne@68: return "runtime: %.3f sec" % (z1+et-at) jpayne@68: jpayne@68: jpayne@68: if __name__ == '__main__': jpayne@68: msg = main() jpayne@68: print(msg) jpayne@68: mainloop()