turtle 海龟作图- example - suite python

turtle - example - suite :

tdemo_wikipedia3.py
This example is
Inspired by the Wikipedia article on turtle
graphics .( See example wikipedia1 for URLs.First we create( ne -1)(1.e.35 in this example ) coples of our first turtle p.Then we let them perform their steps in parallel .
Followed by a complete undo().
----
from turtie import Screen , Turtle , mainioop
from time import perf_counter as clock , sleep
def mn_eck( p , ne , sz ):
turtielist =[ p ]
# create ne -1 additional turtles
for iin range(1, ne ):
q = p.clone()
q.rt(360.0/ne)
turtielist.append( q )
p = q
for l in range( ne ):
c = abs.ne /2.0-1)/( ne °.7)
# let those ne turtles make a step
# In parallel :
fortin turtielist :
t.rt(360./ ne )
t.pencolor(1- c ,0, c )
t.fd( sz )

def main():
s.Screen()
s.bgcolor(" black ")
p = Turtie()
p.speed( O )
p.hideturtie )
p.pencolor(" red ")
p.pensize(3)
s.tracer(36,0)
at.clock()
mn_eck( p ,36,19)
et.clock()
zl = et.at
sleep(1)
at.clock()
while any( t.undobufferentries() for t in s.turties()):
for t in s.turties():
t.undo()
et.clock()
return "runtime :%.3f sec" % (z1 + et - at)

if _name _== "_ main":
msg = main()
print.msg )
mainioop()

posted @ 2023-10-02 12:07  任国强  阅读(41)  评论(0)    收藏  举报