【发布时间】:2015-04-13 22:37:53
【问题描述】:
我正在使用 saveFrame 创建一个图像序列以引入后期效果。在每个循环中,我都在提高 frameRate——我敢肯定这不是最好的方法。在每个循环结束时,我正在保存帧,但 saveFrame 无法跟上我试图保存的逐渐提高的帧速率。任何人都知道如何在不提高 frameRate 的情况下实现我想要的效果,以便 saveFrame 可以跟上?这是我的代码:
```
int w = 640; // canvas size
int h = 480;
int n = 10; // number of grid cells
int d = w/n; // diameter of a grid cell
float depth = 0.5; // relative cell depth
int fr = 100;
int iterator = 0;
boolean doSaveFrames = false;
void setup() {
size(w, h, P3D);
rectMode(CENTER);
background(0);
fill(51, 255, 0);
noStroke();
frameRate(fr);
}
void draw() {
// get coordinates
int xy = frameCount % (n*n);
// shift image in z-direction
if (xy == 0) {
PImage img = get();
background(0);
pushMatrix();
translate(0, 0, -d * depth);
tint(255, 127);
image(img, 0, 0);
popMatrix();
// fr+=iterator*10;
// frameRate(fr); //MH - really cool but I can't export fast enough
iterator++;
}
// scale and rotate the square
scale(d);
translate(xy%n + .5, xy/n + .5, -depth * .5 );
rotate(QUARTER_PI - HALF_PI *int(random(2)));
rotateX(HALF_PI);
// draw the square
rect(0, 0, sqrt(2), depth);
if (doSaveFrames) {
saveFrame("frames/line-######.tga");
}
}
```
【问题讨论】:
-
你能解释一下为什么你要提高帧率吗?因为每次保存时都会越来越快地加快动画速度,这没有任何意义......
-
是的 - 我不想加快每次保存的速度,我想加快整体动画的速度并让 saveFrame 实际上捕捉到速度的增加 - 我想有一种方法可以解决它将保存每第 n 帧,每个周期的持续时间增加。
-
我不遵循,这可能是因为术语:在处理术语中,帧是
draw()方法的开始和结束之间的图形状态,frameRate确定每秒调用draw的频率。您可以通过增加frameRate值来加快动画速度,但是您无法在单帧中捕捉到任何“速度增加”……单个帧没有速度。
标签: processing frame-rate processing.js