Processing.py中的“动画”运动

I need to animate the movement of some linkages in processing. I use 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

enter image description here

评论
Alex55
Alex55

Read the documentation of draw():

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

In processing draw() is executed continuously, thus you do not need a loop. Increment x2 in draw and control the frames per second by 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
点赞
评论