Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created May 18, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamelafox/d754b5b3de1cfc412f0bc28d204c909b to your computer and use it in GitHub Desktop.
Save pamelafox/d754b5b3de1cfc412f0bc28d204c909b to your computer and use it in GitHub Desktop.
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