Created
May 18, 2018 17:07
-
-
Save pamelafox/d754b5b3de1cfc412f0bc28d204c909b to your computer and use it in GitHub Desktop.
RainStormSystem Processing Program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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