Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created April 7, 2014 06:36
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 jkwok91/c6ad1beee3a5683e8327 to your computer and use it in GitHub Desktop.
Save jkwok91/c6ad1beee3a5683e8327 to your computer and use it in GitHub Desktop.
from @shiffman's learning processing
/*
example 10-7
raindropz r fallin from the sky
*/
int numberOfDrops = 200;
Drop[] rainfall = new Drop[numberOfDrops];
void setup() {
size(200, 200);
for (int i = 0; i < numberOfDrops; i++) {
color drop = color(random(255), random(255), 255);
float alpha = random(100);
rainfall[i] = new Drop(random(width), random(height), drop, alpha);
}
}
void draw() {
background(0);
for (int i = 0; i < numberOfDrops; i++) {
Drop d = rainfall[i];
d.move();
if (d.isFallen()) {
color drop = color(random(255), random(255), 255);
float alpha = random(100);
rainfall[i] = new Drop(random(width), -10, drop, alpha);
}
d.display();
}
}
class Drop {
PVector loc;
int rad;
color c;
float a;
Drop(float x, float y, color col, float alpha) {
loc = new PVector(x, y);
rad = 4;
c = col;
a = alpha;
}
boolean isFallen() {
return loc.y > height;
}
void move() {
loc.y++;
}
void display() {
for (int i = 1; i < rad; i++) {
stroke(c, a);
fill(c, a);
ellipse(loc.x, loc.y+(i*2), i*2, i*2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment