-
-
Save jkwok91/c6ad1beee3a5683e8327 to your computer and use it in GitHub Desktop.
from @shiffman's learning processing
This file contains 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
/* | |
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