In this example, I draw a semi-transparent black rectangle to cover the canvas on every run-through of draw(), to gradually cover up and darken the results of the stuff I’d drawn in all previous draw() runs. Shouldn’t the previously-drawn elements (lines and ellipses) eventually turn fully black? Instead, they just turn a dark gray, and stay that way forever. I tried out different draw modes (P2D, P3D), no change. Searched, didn’t find an answer.
Example screenshot, code below:
float x1, y1, x2, y2;
int pad = 20;
int roam = 100;
int radiusE = 8;
void setup() {
size(600, 400);
background(0);
frameRate(30);
x1 = random(0 + pad, width - pad);
y1 = random(0 + pad, height - pad);
}
void draw() {
rectMode(CORNERS);
fill(0, 5); // transparent black
rect(-2, -2, width + 2, height + 2); // draw transparent rect
x2 = random(x1 - roam, x1 + roam);
y2 = random(y1 - roam, y1 + roam);
x2 = constrain(x2, 0 + pad, width - pad);
y2 = constrain(y2, 0 + pad, height - pad);
color color1 = color(random(64, 128), random(64, 128), random(192, 255));
fill(color1);
strokeWeight(2);
stroke(color1);
// draw horiz line
line(x1, y1, x2, y1);
ellipse(x2, y1, radiusE, radiusE);
// draw vertical line
line(x2, y1, x2, y2);
ellipse(x2, y2, radiusE, radiusE);
x1 = x2;
y1 = y2;
}