Skip to content

Instantly share code, notes, and snippets.

@mplacona
Last active August 29, 2015 13:57
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 mplacona/9878484 to your computer and use it in GitHub Desktop.
Save mplacona/9878484 to your computer and use it in GitHub Desktop.
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