ArrayList<Flow> flows;
void setup(){
size(500, 500);
smooth();
frameRate(60);
background(255, 240, 245);
flows = new ArrayList<Flow>();
}
void draw(){
noStroke();
fill(255, 240, 245, 10);
rect(-1, -1, width, height);
if(random(1) < 0.5){
flows.add(new Flow());
}
ArrayList<Flow> killedFlows = new ArrayList<Flow>();
for(Flow flow : flows){
flow.display();
if(flow.isKilled()){
killedFlows.add(flow);
}
}
for(Flow killedFlow : killedFlows){
flows.remove(killedFlow);
}
}
class Flow{
PVector pos;
PVector velocity;
float weight;
float weightSpeed;
float time;
Flow(){
pos = new PVector(random(width), random(height));
float radian = random(TWO_PI);
velocity = new PVector(1.0 * cos(radian), 1.0 * sin(radian));
weight = 0.1;
weightSpeed = 1.0;
}
void display(){
weightSpeed += - sqrt(time) * 0.005;
weight += weightSpeed;
if(weight < 0){weight = 0;}
float forceSize = random(0.1);
float radian = random(TWO_PI);
PVector force = new PVector(forceSize * cos(radian), forceSize * sin(radian));
velocity.add(force);
PVector nextPos = PVector.add(pos, velocity);
stroke(218, 112, 214);
strokeWeight(weight);
line(pos.x, pos.y, nextPos.x, nextPos.y);
pos = nextPos;
time++;
}
boolean isKilled(){
return weight == 0;
}
}