annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/turtledemo/rosette.py @ 69:33d812a61356

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