Write to background while animating shapes
Hello-
I need to create an image during startup() and use that image as background while the app is running and moving 2D shapes across the screen (2D). That much is running in the sample below, but I'm struggling to add one more feature: I need to add to the background while the app is running (like from inside draw()).
In the app below, I want the red ellipses at the bottom of the code to persist onto the background and not fade when draw uses tint/image. I want the black dots to leave the fading/graying tadpole trail, but I do't want those trails to persist. I'm hoping to avoid file i/o. The actual app has a lot more happening and save()/loadImage() would put too much of a load on draw(), even if there were a way to save without the tadpole trails .
PImage bg;
ArrayList lst;
final int MAX = 20;
void setup() {
size(400,300);
fill(200);
ellipse(random(width), random(height), 50, 50);
// draw the rest of bkg.png here
save("bkg.png");
bg = loadImage("bkg.png");
lst = new ArrayList();
}
void draw() {
tint(255, 100);
image(bg,0,0);
if (random(100) < 10 && lst.size() < MAX)
lst.add(new PVector(0,0));
for(int i=0; i<lst.size(); i++) {
PVector pt = (PVector) lst.get(i);
fill(0);
ellipse(pt.x, pt.y, 3, 3);
pt.add(new PVector(random(-1, 7), random(-1, 5)));
if (pt.x > width || pt.y > height)
pt.x = pt.y = 0;
}
if (random(100) < 5 && lst.size() > 10) {
PVector pt = (PVector) lst.get(int(random(lst.size())));
// how to make these ellipses persist in bg (not in bkg.png)?
fill(255,0,0);
ellipse(pt.x, pt.y, 20, 20);
pt.x = pt.y = 0;
}
}