我正试图创建一个与视频同步的25帧秒的图形,我试图每40毫秒保存一帧,但我无法做到每秒钟25帧,但只有一个图像。我试图每40毫秒保存一帧,但我不能每秒钟保存25帧,只能保存一帧图像.有人能帮助我吗?
int t1;
int count;
void setup(){
size(400,100);
background(0);
stroke(255);
fill(250);
line(10,0,10,100);
line(260,0,260,100);
for (int i=10;i<251;i+=10){
t1=millis();
while(millis()-t1 < 40) {
count++;
}
rect(10,50,i,10);
//saveFrame("line-####.png");
}
}
void draw(){}
你代码中的问题是画布只有在一帧结束后才会更新,这意味着你的矩形确实存在,但直到你的 setup() 结束。这就是为什么即使您的代码在绘制新的矩形之前正确地等待了40毫秒,但在for循环结束之前什么也没有显示出来:在结束帧之前,Processing正在等待完成for循环。
然而,在Processing中 绘制() 每秒钟被调用一定的次数,这个次数由函数 帧率() (默认为60)。因此,您可以将 frameRate 设置为 25,并在每次保存图像时 绘制() 被调用。noLoop() 是用来停止调用 绘制()在这种情况下,一旦矩形全部绘制完毕。
int count;
void setup()
{
frameRate(25);
size(400,100);
background(0);
stroke(255);
fill(250);
line(10,0,10,100);
line(260,0,260,100);
}
void draw()
{
rect(10,50,count,10);
saveFrame("line-####.png");
count += 10;
if(count > 251)
{
noLoop();
}
}