ArrayList<Frame> frames;
void setup(){
size(500, 500);
smooth();
frameRate(30);
frames = new ArrayList<Frame>();
frames.add(new Frame());
}
void draw(){
background(255);
translate(width / 2, height / 2);
noStroke();
fill(0);
for(Frame frame: frames){
for(float rad = 0; rad < TWO_PI; rad += PI / 2){
pushMatrix();
rotate(rad);
beginShape();
vertex(frame.dist, 0);
if(frame.dist - frame.range < 0){
vertex(0, 0);
} else {
vertex(frame.dist - frame.range , 0);
vertex(0, frame.dist - frame.range);
}
vertex(0, frame.dist);
endShape(CLOSE);
popMatrix();
}
frame.update();
}
ArrayList<Frame> disappeared = new ArrayList<Frame>();
for(Frame frame: frames){
if(frame.dist >= 1000){
disappeared.add(frame);
}
}
for(Frame frame: disappeared){
frames.remove(frame);
}
if(frames.isEmpty()){
frames.add(new Frame());
} else {
Frame last = frames.get(frames.size() - 1);
if(last.dist > last.range && random(1) < 0.5){
frames.add(new Frame());
}
}
}
class Frame {
float dist;
float range;
float speed;
Frame(){
dist = 0;
range = map(random(1), 0, 1, 5, 20);
speed = 5;
}
void update(){
dist += speed;
}
}