Camcorder

Camcorder will record and play back Processing sketches. You could use this for looking at how users interact with your sketch, or running long renders on different machines, or whatever. I won't try to sell you on it, you'll know when you need it.

As of right now, this is works-for-me quality. I haven't screwed with it too much, but I can pretty much guarantee there's some squirrelly un-serialize code going on in Processing.

Seriously.

Download the library here. (18K)

Yeah...I know...the zip has all the .DS_Store shit in it. I hate when people do that. I'm sorry. I'll fix it later.

Anyway. Back to work. Here's our sketch that gets recorded:

import hipstersinc.camcorder.*;

void setup() {
  size(400, 400, P3D);
  new Camcorder(this, "/tmp/camcorder.dump");
}

void draw() {
  // ... you know the drill.
}
Copy/Paste

That's it. That one line does the trick. It'll wait for your applet to run its course, then write the file when you're done. It isn't doing very much heavy lifting while your code is running, so your performance hit is going to be unnoticeable.

Now, we can do whatever we want with that dump file. We can move it to a faster machine, save it for later...whatever. Here's how we play it back. Let's say we're talking about music visualization that ran in realtime, but now we want to ray-trace the thing and save the frames to disk.

Camcorder cam;

void setup() {
  size(800, 600, "hipstersinc.P5Sunflow");
  Camcorder cam = new Camcorder("/tmp/camcorder.dump");
}

void draw() {
  cam.play(this);
  saveFrame("/tmp/render/frame-####.png");
}
Copy/Paste

No shit! Pretty good. The only other feature that doesn't cover is that play can take a frame number, but by default just cycles through them sequentially. So, if you had 2 machines, you could do something like:

Camcorder cam;
int frameNumber = 0;

void setup() {
  size(800, 600, "hipstersinc.P5Sunflow");
  Camcorder cam = new Camcorder("/tmp/camcorder.dump");
}

void draw() {
  cam.play(this, frameNumber);
  frameNumber += 2;
  g.save( String.format("/tmp/frames/frame-%04d.png", frameNumber));
}
Copy/Paste

And, of course, initialize frameNumber to 1 on the other machine. It doesn't matter if there was a lot of randomness in your code, it all gets captured in the file. Those frames will mesh up like...uhh...whatever. Something good. Something that meshes up pretty well.

Make sure to remember that this only captures and plays back motion. If you're doing something like screwing around with the OpenGL PGraphics you're still going to need to move that code over to your sketch that plays the applet.

I'll rework this document later. I think this library is super-powerful, but I'm feeling pretty lazy at the moment.