I want to save the current frame as PDF, but only if a button has been pressed in that frame as well. The examples (e.g. the "PDF Files from 3D Geometry (With Screen Display)" from https://processing.org/reference/libraries/pdf/ appear to do something similar, but are essentially different: they use a variable to then save the NEXT frame.
I'd like to do something like the sample from https://processing.org/reference/beginRaw_.html (below) - to call beginRaw() every frame, and call endRaw() only if a key was pressed - but if no key was pressed at the end of draw(), i'd like to dispose of the recording of the current frame. Since there is not call to something like "disposeRaw()", beginRaw() creates a new PDF file each frame.
import processing.pdf.*;
Boolean saveFrame = false;
void setup() {
size(400, 400, P2D);
}
void draw() {
beginRaw(PDF, "raw"+frameCount+".pdf");
line(pmouseX, pmouseY, mouseX, mouseY);
if (saveFrame == true) endRaw();
else // disposeRaw();
}
void keyPressed() {
if (key == ' ') {
saveFrame = true;
}
}
How would I dispose of PDF file creation for frames which already called beginRaw()?