Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RainStormSystem Processing Program
// A simple Particle class
class RainDrop {
int x;
int y;
RainDrop(int startX, int startY) {
this.x = startX;
this.y = startY;
}
void run() {
update();
display();
}
// Method to update position
void update() {
y += 3;
}
// Method to display
void display() {
noStroke();
fill(240, 240, 255, 100);
ellipse(this.x, this.y, 2, 8);
}
// Is the drop still around?
boolean isDone() {
if (this.y > height) {
return true;
} else {
return false;
}
}
}
// A class to describe a group of Particles
// An ArrayList is used to manage the list of Particles
class RainStorm {
ArrayList<RainDrop> drops;
int startY = 0;
int endY = height;
RainStorm() {
this.drops = new ArrayList<RainDrop>();
}
void addDrop() {
int startX = (int) random(0, width);
drops.add(new RainDrop(startX, startY));
}
void run() {
for (int i = drops.size()-1; i >= 0; i--) {
RainDrop drop = drops.get(i);
drop.run();
if (drop.isDone()) {
drops.remove(i);
}
}
}
}
/**
* Raindrops are generated each cycle through draw()
* and fade over time.
* A RainStorm object manages a variable size (ArrayList)
* list of raindrop.
*/
RainStorm rainStorm;
void setup() {
size(640, 360);
rainStorm = new RainStorm();
}
void draw() {
background(72, 102, 112);
rainStorm.addDrop();
rainStorm.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.