'Animating' Processing.py 的运动

'Animating' movement in Processing.py

我需要为 processing 中的某些链接设置动画。我用 processing.py

我尝试了一个玩具示例,我在屏幕上移动了一条线段。我的想法是: 1)画线 2)延迟一秒钟 3)擦除屏幕 4)改变线的位置 5) 重复。

但是我的代码不起作用。它递增,但最终只显示最终行位置。我从来没有看到中间步骤线。

import math

def setup():
    size(800, 500)
    noLoop()

def draw():

    line(100,100,200,200)
    delay(100)

    x1,y1,x2,y2 = (100,100,200,200)

    for chunk in range(10,100,10):
        print(chunk)
        background(255)
        line(x1,y1,x2,y2)
        delay(1000)
        x2 += chunk

阅读 draw() 的文档:

[...] All Processing programs update the screen at the end of draw(), never earlier.

In processing draw() 连续执行,因此不需要循环。在 draw 中增加 x2 并通过 frameRate

控制每秒帧数
x1,y1,x2,y2 = (100,100,200,200)
chunk = 10

def setup():
    size(800, 500)
    frameRate(10)

def draw():
    global x2

    background(255)
    line(x1,y1,x2,y2)
    x2 += chunk