eddy
@author
float dir;
ArrayList<Particle> particles;
void setup(){
size(640, 480);
colorMode(HSB, 360, 100, 100);
mousePressed();
}
void mousePressed(){
background(random(360), random(30), random(100));
stroke(random(360), random(30), random(100));
strokeWeight(1);
particles = new ArrayList<Particle>();
for(int i = 0; i < 500; i++){
particles.add(new Particle());
}
dir = random(1) < 0.5 ? -1: 1;
}
void draw(){
translate(width / 2, height / 2);
for(Particle p: particles){
p.display();
}
}
class Particle{
PVector loc;
Particle(){
float locAng = random(TWO_PI);
float radious = sqrt(sq(width) + sq(height)) / 2;
loc = new PVector(radious * cos(locAng), radious * sin(locAng));
}
void display(){
PVector vel = PVector.mult(loc, -1);
vel.normalize();
vel.limit(0.5);
PVector nLoc = PVector.add(loc, vel);
vel.normalize();
vel.limit(4);
vel.rotate(dir * HALF_PI);
nLoc.add(vel);
line(loc.x, loc.y, nLoc.x, nLoc.y);
loc = nLoc;
}
}