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