Created
December 16, 2016 13:15
-
-
Save petar-dambovaliev/df8792ae4a0be3989ba5a9bece273c67 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
//To work on the page you need : | |
//div id=canvas | |
//lookout for your background because the flakes are grey | |
window.onload = function() | |
{ | |
var canvas= document.getElementById("canvas"); | |
var context = canvas.getContext("2d"); | |
var width=window.innerWidth; | |
var height=window.innerHeight; | |
canvas.width=width; | |
canvas.height=height; | |
var snowFlakesCount=70; | |
var particles=[]; | |
for (i = 0; i < snowFlakesCount; i++) { | |
particles.push({ | |
x:Math.random()*width , | |
y:Math.random()*height , | |
r:Math.random()*5+1, | |
d:Math.random()*snowFlakesCount | |
}); | |
} | |
function draw() | |
{ | |
context.clearRect(0,0,width,height); | |
context.fillStyle="rgba(240,240,240,0.8)"; | |
context.beginPath(); | |
for (i = 0; i < snowFlakesCount; i++) { | |
var p =particles[i]; | |
context.moveTo(p.x,p.y); | |
context.arc(p.x,p.y,p.r,0,Math.PI * 2,true); | |
} | |
context.fill(); | |
update(); | |
} | |
function update() | |
{ | |
for (i = 0; i < snowFlakesCount; i++) { | |
var p=particles[i]; | |
p.y +=3; | |
p.x +=1; | |
if ( p.y>height) { | |
particles[i].y = 0; | |
} | |
if (p.x > width) { | |
p.x=0; | |
} | |
} | |
} | |
setInterval(draw,20); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment