我正在 Pyzo 中做一个练习项目,并且我在使用 turtle.tracer() 时遇到了一些问题。
当 n =/= 0 或 1 时,我遇到了屏幕上的对象开始闪烁的问题。
import turtle
sketcher = turtle.Turtle()
canvas = turtle.Screen()
sketcher.speed(0)
sketcher.hideturtle()
def drawPinwheelAnimation(length):
sketcher.setheading(90)
backwardLength = length
lengthChange = 1
while(True):
canvas.tracer(36)
drawPinwheel(0, 0, length, backwardLength)
drawPinwheel(3*length, 0, length, backwardLength)
drawPinwheel(0, 3*length, length, backwardLength)
drawPinwheel(-3*length, 0, length, backwardLength)
drawPinwheel(0, -3*length, length, backwardLength)
canvas.update()
backwardLength += lengthChange
if(backwardLength == (1.5*length) or backwardLength == (0.5*length)):
lengthChange *= -1
sketcher.clear()
def drawSwingingPinwheel(xPos, yPos, initialLength):
while(True):
drawPinwheel(xPos, yPos, forwardLength, backwardLength)
backwardLength += lengthChange
if(backwardLength == (1.5*initialLength) or backwardLength == (0.5*initialLength)):
lengthChange *= -1
sketcher.clear()
def drawPinwheel(xPos, yPos, fdLength, bkLength):
sketcher.penup()
sketcher.setpos(xPos, yPos)
sketcher.pendown()
for side in range(12):
sketcher.fd(fdLength)
sketcher.bk(bkLength)
sketcher.rt(30)
drawPinwheelAnimation(50)
turtle.mainloop()
当n = 1时,没有闪烁,但这也意味着动画无论如何都以基本速度进行,因此没有效果。当 n = 0 时,没有闪烁。但是,这对我的目的来说太快了。我尝试更改“延迟”值,但无济于事:
canvas.tracer(0, 1000) #Changing the second value to 1000 has no notable difference.
drawPinwheel(0, 0, length, backwardLength)
drawPinwheel(3*length, 0, length, backwardLength)
drawPinwheel(0, 3*length, length, backwardLength)
drawPinwheel(-3*length, 0, length, backwardLength)
drawPinwheel(0, -3*length, length, backwardLength)
canvas.update()
我在这一点上很困。我不确定,我可能缺少一个非常明显的解决方案。
谢谢!