我正在尝试日食,但遇到了无法解决的奇怪事件。 while循环仅在存在打印语句的情况下有效。但是,一旦删除它,while循环将停止工作(在这种情况下,它将停止更新乌龟)。我已经尝试谷歌这个问题无济于事。因此,我想就此寻求他人的帮助。提前非常感谢:)
PS。我只从脚本中提取了必要的代码才能上传。目前没有错误。
# Initialise frame-tracking for pointer drawing
secondPerFrame = 0.04
nextFrame =0
# Initialise screen
screen = turtle.Screen()
screen.setup(600,600)
screen.tracer(0)
screen.colormode(255)
# Initialise turtle for drawing of pointer
pointerTurt = turtle.Turtle()
pointerTurt.speed(0)
pointerTurt.width(10)
pointerTurt.hideturtle()
# Initialise variables
wheelRadius = 250
startForce = 30
def update_pointer_direction():
pointerTurt.clear()
pointerTurt.goto(0,0)
pointerTurt.pendown()
pointerTurt.forward(wheelRadius *0.75)
pointerTurt.penup()
screen.update()
def decay_wheel_spinforce():
global startForce
if (startForce > 0):
partialStartForce = startForce * 0.005
startForce -= random.random() * partialStartForce
if (startForce < 0.005):
startForce =0
while True :
if (nextFrame < time.perf_counter()):
update_pointer_direction()
nextFrame = time.perf_counter() + secondPerFrame
print()
decay_wheel_spinforce()
pointerTurt.left(startForce)
答案 0 :(得分:0)
我意识到在玩了几周之后我犯了一个非常新手的错误。 fade_wheel_spinforce()将以不受限制的速度运行,并很快将其设置为0。此问题通过包含time.sleep(0.01)来解决,以确保该函数不会运行得太快。