Last active
August 29, 2015 13:57
-
-
Save mplacona/9878484 to your computer and use it in GitHub Desktop.
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
void snowFall(){ | |
// draw background on canvas | |
ctx.fillStyle="#000"; | |
ctx.fillRect(0,0,W,H); | |
//drawing intitial snowflakes on canvas | |
ctx.fillStyle = "#fff"; | |
// rain | |
ctx.beginPath(); | |
for(var i = 0; i < maxFlakes; i++){ | |
var f = flakes[i]; | |
ctx.moveTo(f._x, f._y); | |
ctx.arc(f._x, f._y, f._r, 0, math.PI*2, true); | |
} | |
ctx.fill(); | |
//moving snow flakes | |
var angl=0; | |
for(var i=0; i < maxFlakes; i++){ | |
angl+=0.1; | |
var f=flakes[i]; | |
f._x +=math.sin(angl).abs() + 0.1 ; | |
f._y += math.cos(angl).abs() * speed; | |
//resetting snowflakes when they are out of frame | |
if(f._x > W || f._x < 0 || f._y > H){ | |
f._x = rng.nextDouble() * W; | |
f._y=-10.0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment