/**
* PGraphics arrayCopy() (v1.1)
* GoToLoop (2018/Jul/25)
* Discourse.Processing.org/t/weird-issue-with-pgraphics/2063/4
*/
static final String FILENAME = "balls.", EXT = ".jpg";
static final String FC = "Frames: ", SC = " - Shots: ";
static final int BALLS = 200, DIAM = 20, RAD = DIAM >> 1;
PGraphics left, right;
void setup() {
size(640, 480);
left = createGraphics(width >> 1, height);
right = createGraphics(width >> 1, height);
left.beginDraw();
left.background((color) random(#000000));
left.endDraw();
right.beginDraw();
right.background((color) random(#000000));
right.endDraw();
set(width >> 1, 0, right);
}
void draw() {
final int shots = frameCount / BALLS;
final String fc = FC + frameCount, sc = SC + shots;
getSurface().setTitle(fc + sc);
left.beginDraw();
final float x = random(RAD, left.width - RAD);
final float y = random(RAD, left.height - RAD);
left.ellipse(x, y, DIAM, DIAM);
if (frameCount % BALLS == 0) {
left.loadPixels();
arrayCopy(left.pixels, right.pixels);
right.updatePixels();
set(width >> 1, 0, right);
final String filename = FILENAME + nf(shots, 3) + EXT;
right.save(dataPath(filename));
left.background((color) random(#000000));
}
left.endDraw();
set(0, 0, left);
}