annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/turtledemo/rosette.py @ 68:5028fdace37b

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