forked from dcheesman/LEDStripController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Natalie Landrey
authored and
Natalie Landrey
committed
Dec 24, 2013
1 parent
3b39ef2
commit 5484b94
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class Snow extends Effect{ | ||
// how fast the flakes should fall | ||
float fallSpeed = .02; | ||
|
||
//Array of points for the flakes | ||
PVector[] flakes; | ||
|
||
Snow(int _millis){ | ||
super(_millis); | ||
|
||
//initialize the array to hold the flakes | ||
flakes = new PVector[rows*cols/8]; | ||
for(int i=0; i<flakes.length; i++){ | ||
// put each new flake in a new location | ||
flakes[i] = new PVector(floor(random(cols)), random(-5,rows/2)); | ||
} | ||
} | ||
|
||
void update(){ | ||
// do any commands in the Effect class update function | ||
imageBuffer.beginDraw(); | ||
|
||
super.update(); | ||
|
||
// fade out the previous image to transparent | ||
imageBuffer.background(0,0); | ||
|
||
// move the flakes down | ||
updateFlakes(); | ||
|
||
// draw flakes to image buffer | ||
imageBuffer.fill(255); | ||
imageBuffer.noStroke(); | ||
|
||
for(PVector f : flakes){ | ||
imageBuffer.rect(f.x, f.y, 1, 1); | ||
} | ||
|
||
imageBuffer.endDraw(); | ||
} | ||
|
||
// makes the flakes move down | ||
void updateFlakes(){ | ||
for(int i =0; i<flakes.length; i++){ | ||
// if it goes past the end start somewhere new | ||
if(flakes[i].y + fallSpeed > rows || random(1)<.01){ | ||
flakes[i] = new PVector(floor(random(cols)), random(-5, rows)); | ||
} else { | ||
flakes[i].y += fallSpeed + random(.1); | ||
} | ||
} | ||
} | ||
} |