Hey There !
You have got a really cool animation going !
Like it was pointed out saveFrame()
is the way to go.
Some great solutions have been pointed out how to utilize this well, but I would like to add my solution too !
As your looking to capture the animation while its running I recommend utilizing frameCount
utilizing frameCount
will just limit by how many frames you capture the animation playing. Be it TICK_TIME = 60
frames, TICK_TIME = 120
or TICK_TIME = 10
!
Here’s a more verbose example.
if (frameCount % TICK_TIME == 0) {
saveFrame()
}
Anyway here’s the full code, that way you can see really at action what I am trying to explain.
Any further questions let us know !
Happy coding
float blueX;
float blueY;
float redX;
float redY;
int frames;
final int TICK = 10;
void setup() {
size(500, 500);
frames = 0;
blueX = width*.25;
blueY = height/2;
redX = width*.75;
redY = height/2;
background(255);
}
void draw() {
stroke(0, 0, 255);
strokeWeight(2);
blueX += random(-2, 2);
blueY += random(-2, 2);
if (blueX < 0) {
blueX = width;
}
if (blueX > width) {
blueX = 0;
}
if (blueY < 0) {
blueY = height;
}
if (blueY > height) {
blueY = 0;
}
point(blueX, blueY);
stroke(255, 0, 0);
strokeWeight(2);
redX += random(-2, 2);
redY += random(-2, 2);
if (redX < 0) {
redX = width;
}
if (redX > width) {
redX = 0;
}
if (redY < 0) {
redY = height;
}
if (redY > height) {
redY = 0;
}
point(redX, redY);
if (frameCount % TICK == 0) {
saveFrame("animation-" + (frames++) + ".jpg");
}
}