Code:
Triangle [] t;
int playhead = 0;
void setup(){
size(200, 200);
smooth();
t = new Triangle[10];
for(int i = 0; i < t.length; i++){
t[i] = new Triangle(random(width), random(height), random(width), random(height), random(width), random(height));
t[i].alpha = random(255);
}
}
void draw(){
background(200);
for(int i = 0; i < t.length; i++){
t[i].draw();
if(t[i].alpha <= 0){
t[i] = new Triangle(random(width), random(height), random(width), random(height), random(width), random(height));
}
}
}
class Triangle{
float x0,y0,x1,y1,x2,y2;
float r,g,b,alpha;
Triangle(float x0, float y0, float x1, float y1, float x2, float y2){
this.x0 = x0;
this.y0 = y0;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
alpha = 255f;
r = random(200, 255);
g = random(200, 255);
b = random(200, 255);
}
void draw(){
fill(r, g, b, alpha);
stroke(0, alpha);
triangle(x0, y0, x1, y1, x2, y2);
alpha -= 0.5;
}
}
I'm leaving it to you to figure out a way to get the new triangles to come in on top of the triangles on screen.
You're going to have to either manually move the new triangles to the beginning of the list, or perhaps sort the list of triangles based on their alpha value.