I've implemented these 2 methods and have found them invaluable.
They enable (obviously!) one to stop the recording of say a PDF and then resume that same recording without a recorder.endFrame occuring. This means that you can build an interactive drawing over a number of frames, but contained within a single PDF frame.
It functions the same as aiexport's takeSnapShot and dumpSnapShot methods for dealing with accumulative images.
Is this likely to be causing problems elsewhere?
Here's an example of its implementation:
Code:
import processing.pdf.*;
void setup() {
size (400, 400);
}
int fileno=1;
void draw() {
pauseRecord(); // if we are recording stop!
// Things not to appear in the pdf
background(255);
stroke((int)random(0,255));
rect(width/2,height/2,mouseY,mouseX);
resumeRecord();
// This will all appear in the pdf
stroke((int)random(0,255));
ellipse (width/2, height/2, mouseX, mouseY);
}
void mousePressed() {
beginRecord(PDF, "foo" + fileno++ + ".pdf");
background(255); // set the intial state of the pdf
}
void mouseReleased() {
endRecord(); // finish up this pdf
}
The following code basically overrides and extends functionality.
Code:
// Overriden methods from processing.core.PApplet
PGraphics container; // temporary storage for recorder
public PGraphics beginRecord(String renderer, String filename) {
filename = insertFrame(filename);
PGraphics rec = createGraphics(width, height, renderer, filename);
beginRecord(rec);
return rec;
}
public void beginRecord(PGraphics recorder) {
this.recorder = recorder;
recorder.beginFrame();
}
public void endRecord() {
if (recorder != null) {
recorder.endFrame();
recorder.dispose();
recorder = null;
container = null;
}
}
public void pauseRecord() {
if (recorder != null) {
container = recorder;
recorder = null;
}
}
public void resumeRecord() {
if (container != null) {
beginRecord(container);
}
}