Skip to content

Instantly share code, notes, and snippets.

@kookxiang
Last active December 23, 2017 17:54
Show Gist options
  • Save kookxiang/09962c6423a96b71b71fe0bf605e69f9 to your computer and use it in GitHub Desktop.
Save kookxiang/09962c6423a96b71b71fe0bf605e69f9 to your computer and use it in GitHub Desktop.
Snow Effect for Winter~ (aka White Album Season)
body {
margin: 0;
background: #202020;
}
body > .snow {
display: block;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
pointer-events: none;
}
! function() {
function n() {
e.width = window.innerWidth;
e.height = window.innerHeight;
r = Math.round(window.innerWidth * window.innerHeight / 1e4)
}
function i() {
var n = window.innerWidth,
d = window.innerHeight,
h = e.getContext("2d");
h.clearRect(0, 0, n, d);
h.fillStyle = "rgba(255, 255, 255, 0.7)";
h.beginPath();
a += .01;
for (var s = 0; r > s; s++) {
var m = o[s];
h.moveTo(m.x, m.y);
h.arc(m.x, m.y, m.radius, 0, 2 * Math.PI, !0);
m.y += Math.cos(a) + m.radius / 2;
m.x += Math.sin(a * m.direction);
if (m.x > n + 5 || -5 > m.x || m.y > d)
if (s % 3 > 0) {
o[s].x = Math.random() * n;
o[s].y = -10
} else if (Math.sin(a * m.direction) > 0) {
o[s].x = -5;
o[s].y = Math.random() * d
} else {
o[s].x = n + 5;
o[s].y = Math.random() * d
}
}
h.fill();
t(i)
}
var e = document.createElement("canvas"),
t = requestAnimationFrame || msRequestAnimationFrame || function(n) {
setTimeout(n, 16)
},
a = 0,
r = 0,
o = [];
n();
e.className = "snow";
document.body.appendChild(e);
for (var d = 0; r > d; d++) o.push({
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
radius: 4 * Math.random() + 1,
direction: 2 * Math.random() - .5
});
addEventListener("resize", n);
t(i)
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment