I want to export still images from this animation and I don’t know how to do it. This code make interesting images in different moments and I would like to frozen and export them to print them in HQ. Could you please help me? Thank you so much!
you can add boolean or mousePressed()… etc to your sketch
//https://processing.org/reference/saveFrame_.html
int x = 0;
void draw() {
background(204);
if (x < 100) {
line(x, 0, x, 100);
x = x + 1;
} else {
noLoop();
}
// Saves each frame as line-000001.png, line-000002.png, etc.
saveFrame("line-######.png");
}
I save the frames from the animation and then process them with ffmpeg to create a video. You can see the finished product here: https://www.youtube.com/watch?v=Rwttllcf86I
Thank you so much! I added this code at the end and it worked:
if (mousePressed ==true) {
saveFrame();
}
Now I have two another questions about printing:
I would like to work with cmyk colors, but I think is not possible with Processing. Should I choose the cmyk colors that I need and then convert them to RGB colors to make sketches ready to be successfully printed?
To get a 300 dpi picture, should I multiply 4.166 times size and points to get a bigger picture or there is a better way?
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.
I have got a pdf with this code, pressing letter “q” and stopping animation. Effectively, picture has 300 ppp when I open it in photoshop. I should be happy… but I am not because what I was looking for something to get many frames while the animation is going on, as I got with
if (mousePressed ==true) {
saveFrame();
}
Could you please help me? Here is my code:
import processing.pdf.*;
float x;
float y;
float r;
float g;
float b;
void setup() {
size(300, 300);
x = width / 2;
y = height / 2;
r = random(255);
g = random(255);
b = random(255);
background(50);
beginRecord(PDF, "everything.pdf");
}
void draw() {
for (int i = 0; i < 1000; i++) {
step();
}
}
void step() {
x += random(-1, 1);
y += random(-1, 1);
x = constrain(x, 0, width);
y = constrain(y, 0, height);
r += random(-1, 1);
g += random(-1, 1);
b += random(-1, 1);
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
stroke(r, g, b);
point(x, y);
}
void keyPressed() {
if (key == 'q') {
endRecord();
exit();
}
}
Now I have tried with this again and I have been able to save many pdf files pressing the mouse, but they are empty. I am really doing my best with turorials, but I don’t get the result. Could you please help me?
import processing.pdf.*;
boolean record;
float x;
float y;
float r;
float g;
float b;
void setup() {
size(300, 300);
x = width / 2;
y = height / 2;
r = random(255);
g = random(255);
b = random(255);
background(50);
}
void draw() {
if (record) {
beginRecord(PDF, "frame-####.pdf");
}
for (int i = 0; i < 1000; i++) {
step();
}
}
void step() {
x += random(-1, 1);
y += random(-1, 1);
x = constrain(x, 0, width);
y = constrain(y, 0, height);
r += random(-1, 1);
g += random(-1, 1);
b += random(-1, 1);
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
stroke(r, g, b);
point(x, y);
if (record) {
endRecord();
record = false;
}
}
void mousePressed() {
record = true;
}
You are ending the PDF record after a loop count of zero so you have only one loop displayed in the frame and that is what you record.
I added a print statement so you can see this.
Click here for code
import processing.pdf.*;
boolean record;
float x;
float y;
float r;
float g;
float b;
int num;
void setup() {
size(300, 300);
x = width / 2;
y = height / 2;
r = random(255);
g = random(255);
b = random(255);
background(50);
}
void draw() {
if (record) {
beginRecord(PDF, "frame-####.pdf");
}
for (int i = 0; i < 1000; i++) {
num = i; //store i in num for later
step();
}
}
void step() {
x += random(-1, 1);
y += random(-1, 1);
x = constrain(x, 0, width);
y = constrain(y, 0, height);
r += random(-1, 1);
g += random(-1, 1);
b += random(-1, 1);
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
stroke(r, g, b);
point(x, y);
if (record) {
endRecord();
println(num); // Loop count where recording ends
record = false;
}
}
void mousePressed() {
record = true;
}
``
Consider using a PGraphics buffer and saving that as a PDF or an image.