// Make it snow in your site // See https://github.com/Canop/snow window.snow = (function(){ var ctx, canvas, W, H, heights = [], n = 0, timer, fall; function resetScreen(){ if (!canvas) { window.addEventListener("resize", resetScreen); canvas = document.createElement("canvas"); document.body.appendChild(canvas); } W = window.innerWidth; H = window.innerHeight; canvas.id = "snow-canvas"; canvas.style.pointerEvents = "none"; canvas.style.position = "fixed"; canvas.style.zIndex = 5000; // todo make it modifiable canvas.style.left = 0; canvas.style.right = 0; canvas.style.top = 0; canvas.style.bottom = 0; canvas.width = W; canvas.height = H; ctx = canvas.getContext("2d"); if (heights.length1) { heights[i] -=.7*d; heights[i-1] +=.3*d; if (i>1) heights[i-2] +=.2*d; if (i>2) heights[i-3] +=.1*d; } } } else { for (var i=0; i1) { heights[i] -=.7*d; heights[i+1] +=.3*d; if (i1) { this.speed = fall.minSpeed + (fall.maxSpeed-fall.minSpeed)*(this.radius-1)/(fall.maxRadius-1); } else { this.speed = rnd(fall.minSpeed, fall.maxSpeed); } this.omega = rnd(.02, .13); } Flake.prototype.draw = function(){ ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, 2*Math.PI, false); ctx.fill(); } Flake.prototype.update = function(fall){ this.y += this.speed; var i = Math.round(this.x), h; if (i<0) h = heights[0]; else if (i>=W) h = heights[W-1]; else h = heights[i]; if (this.y >= H-h) { if (i>=0 && i