xxxxxxxxxx
ArrayList<Rain> rains = new ArrayList<Rain>();
void setup() {
size(640, 640);
noStroke();
}
void draw() {
background(255);
rains.add(new Rain());
rains.add(new Rain());
for (int i = 0; i < rains.size (); i++) {
Rain r = rains.get(i);
float boundary = 100-abs(cos(radians(r.location.x/2)))*10;
r.checkBoundary(boundary);
}
}
class Rain {
PVector location;
PVector acceleration;
PVector velocity;
PVector gravityWind;
float a;
float mass;
float opacity = 200;
Rain() {
a = random(3,6);
location = new PVector(random(-300, width+300), -a-30);
velocity = new PVector();
acceleration = new PVector();
mass = 40/a;
}
void applyForce(PVector force) {
acceleration.add(PVector.div(force, mass));
}
void checkBoundary(float boundary) {
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
if (location.y > height-boundary) {
velocity.y *= 0.8;
velocity.x = 0;
fill(93, 138, 168, opacity);
opacity--;
if (opacity > 0) {
ellipse(location.x, location.y, a, a);
} else {
rains.remove(this);
}
} else {
gravityWind = new PVector(map(mouseX, 0, width, -0.05, 0.05), map(mouseY, 0, height, 0.4, 0.5));
fill(93, 138, 168);
for (int i = 2; i<a;i++) {
ellipse(location.x, location.y+i*4, i*2, i*2);
}
applyForce(gravityWind);
}
}
}