1
我已经写了下面的python代码来创建使用python turtle的旋转图形的动画。我面临的问题是,动画不能正确同步。我不想让人们知道事情是如何旋转的。所以,我必须仔细选择turtle.tracer
命令中的帧速率。那么,如果你仔细观察,每个值r
创建一个旋转,所以我必须更新每个r
结束时的屏幕。对于r
的每个值,r
的循环内有1202次迭代。但是这不会产生预期的效果。如何使用turtle-graphics模块同步动画?
我该怎么做才能纠正这个问题?
import turtle
import math
am = turtle
am.ht()
am.tracer(1202,0)
for r in range(0,600):
#axes
am.pu()
am.setpos(0,500)
am.pd()
am.setpos(0,-500)
am.pu()
am.setpos(-650,0)
am.pd()
am.setpos(0,0)
am.write("0",align="right",font=("Times New Roman",14,"normal"))
am.setpos(650,0)
am.pu()
am.setpos(-300*math.cos(r*math.pi/100),300*math.sin(r*math.pi/100))
am.pd()
#axes
am.pencolor("red")
for x in range(-300,301):
g=math.sin(x)
t=math.cos(x)
y =100*g*t*math.sin(2*(x**2)*math.pi/100)
am.setpos(x*math.cos(r*math.pi/100)+y*math.sin(r*math.pi/100),-x*math.sin(r*math.pi/100)+y*math.cos(r*math.pi/100))
#if(x%4==0):
#am.write(x)
am.pu()
am.setpos(-300*math.sin(r*math.pi/100),-300*math.cos(r*math.pi/100))
am.pd()
am.pencolor("blue")
for y in range(-300,301):
c=math.sin(y)
d=math.cos(y)
x =100*c*d*math.cos(2*(y**2)*math.pi/100)
am.setpos(x*math.cos(r*math.pi/100)+y*math.sin(r*math.pi/100),-x*math.sin(r*math.pi/100)+y*math.cos(r*math.pi/100))
am.reset()
am.exitonclick()
你想要完全同步什么?如果你不想确切地显示事物的旋转方向,你想显示什么_do_? Turtle-graphics是绘制动画帧的一种相当慢的方式,需要花费几秒钟来绘制图形的每个“帧”,因此如果不是不可能的话,使用它生成真正的动画将很困难。文件中提到的“动画”与绘制线条和移动乌龟的速度有关(即使速度设置得尽可能快,速度都很慢)。 – martineau