中间有一段时间卡顿,最后图片会显示完整,但是不知道怎么修改
问题来源是turtle.tracer(0)这个代码的问题
#圣诞树
import turtle as t
import random,time,datetime,math
t.hideturtle()
t.setup(1000,600,100,0)
t.tracer(0)
def bg(size):
t.colormode(255)
a=random.randint(30,70)
b=random.randint(10,25)
c=random.randint(10,25)
t.bgcolor(a,b,c)
t.pendown()
t.color("yellow","yellow")
t.begin_fill()
for i in range (5):
t.forward(size)
t.right(144)
t.end_fill()
def koch(size,n):
if n==0:
t.fd(size)
else:
for angle in [0,60,-120,60]:
t.left(angle)
koch(size/3, n-1)
def main(size):
t.pendown()
t.color("white","white")
t.begin_fill()
level=2
koch(size,level)
t.right(120)
koch(size,level)
t.right(120)
koch(size,level)
t.end_fill()
def xuedi1():
t.penup()
t.goto(-530,-260)
t.pendown()
t.pensize(87)
t.color("white")
t.goto(530,-260)
t.pensize(5)
t.goto(530,-220)
t.left(90)
def xuedi2():
t.circle(random.randint(0,6),180)
t.right(180)
for i in range (75):
t.penup()
t.goto(random.randint(-485,485),random.randint(-100,290))
bg(10)
t.penup()
t.goto(random.randint(-485,485),random.randint(-290,290))
main(10)
t.penup()
t.goto(random.randint(-485,485),random.randint(-290,290))
main(10)
time.sleep(0.025)
xuedi1()
for i in range(200):
xuedi2()
time.sleep(0.025)
def wjx():
t.penup()
t.goto(225,250)
t.pendown()
t.pensize(25)
t.color("yellow","pink")
t.begin_fill()
for i in range (5):
t.forward(50)
t.right(144)
t.end_fill()
def sdssg(angle):
t.penup()
t.goto(250,250)
t.colormode(255)
a=random.randint(90,100)
b=random.randint(100,150)
c=random.randint(30,80)
t.color(a,b,c)
t.begin_fill()
t.pendown()
for i in range(6):
t.setheading(0)
t.right(90+angle)
t.forward(80)
t.left(90+angle)
t.forward(20)
t.penup()
t.goto(250,250)
t.pendown()
for i in range(6):
t.setheading(0)
t.right(90-angle)
t.forward(80)
t.left(90-angle)
t.forward(-20)
x=angle
long=240-960*(math.sin(math.radians(x)))
t.forward(long)
t.end_fill()
for i in range (4):
sdssg(35-5*i)
time.sleep(0.5)
wjx()
def write():
t.penup()
t.goto(-400,200)
t.pendown()
t.pencolor("white")
t.write("Happy",font=("arial",66,"normal"))
t.penup()
t.goto(-350,100)
t.pendown()
t.pencolor("yellow")
t.write("Christmas",font=("arial",66,"normal"))
write()
t.done()
运行结果及报错内容
我的解答思路和尝试过的方法
怎样可以使前面的画图加快,后面的慢下来,又不会中间卡顿,这个是中间一段代码出现的问题