简体   繁体   English

Processing.py 中的“动画”运动

[英]'Animating' movement in Processing.py

I need to animate the movement of some linkages in processing .我需要动画processing中的一些链接的运动。 I use processing.py我使用processing.py

I tried a toy example where I move a line segment across the screen.我尝试了一个玩具示例,在该示例中我在屏幕上移动了一条线段。 My idea was to: 1) draw the line 2) delay for a second 3) erase the screen 4) change the location of the line 5) repeat.我的想法是:1)画线 2)延迟一秒钟 3)擦除屏幕 4)改变线的位置 5)重复。

But my code doesn't work.但是我的代码不起作用。 It increments through, but ultimately only shows the final line location.它递增,但最终只显示最终的行位置。 I never see the intermediate step lines.我从来没有看到中间步骤线。

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

在此处输入图像描述

Read the documentation of draw() :阅读draw()的文档:

[...] All Processing programs update the screen at the end of draw() , never earlier. [...] 所有处理程序都会在draw()结束时更新屏幕,绝不会更早。

In processing draw() is executed continuously, thus you do not need a loop.在处理draw()连续执行,因此您不需要循环。 Increment x2 in draw and control the frames per second by frameRatedraw中增加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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM