【Processing】画像をフレームごとに保存する

saveFrame関数で画像をフレームごとに保存する。

int x = 100;
int y = 100;
int xspeed = 3;
int yspeed = 3;
int r = 50;
int R, G, B;

void setup() {
  size(640, 360);
}

void draw() {
  background(0);
  
  x = x + xspeed;
  y = y + yspeed;
  R = (int) random(255) + 1;
  G = (int) random(255) + 1;
  B = (int) random(255) + 1;
  
  if ((x+r > width) || (x-r < 0)) {
    fill(R, G, B);
    xspeed = xspeed * -1;
  }
  if ((y+r > height) || (y-r < 0)) {
    fill(R, G, B);
    yspeed = yspeed * -1;
  }
  
  noStroke();
  circle(x, y, r*2);
  
  saveFrame("frames/####.png");
  if (frameCount >= 60*10) {
    exit();
  }
}

参考

saveFrame() \ Language (API) \ Processing 3+
Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted ...

コメント

タイトルとURLをコピーしました