Created
January 25, 2017 04:48
-
-
Save 9999years/8fd0184530fcbbe494ffc306bab8654b 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
var els = [], | |
g = { | |
img: document.getElementsByTagName("img")[0], | |
time: 0, | |
amt: 20, | |
amin: 5 /* amp */, | |
amax: 10, | |
ramin: 1 /* rot amp */, | |
ramax: 50, | |
pmin: 1 /* period */, | |
pmax: 10, | |
rpmin: 1 /* rot period */, | |
rpmax: 50 | |
}; | |
function randf(min,max) { return Math.random()*(max-min)+min; } | |
function randSign() { return Math.round(Math.random()) ? -1 : 1; } | |
function sin(amp,period) { return amp*Math.sin((g.time/period)*2*Math.PI); } | |
function generateVariables() { | |
for(var i = els.length; i < g.amt; i++) { | |
els.push( | |
{ | |
el: document.body.appendChild(g.img.cloneNode()), | |
t: randf(0, document.body.scrollHeight), | |
l: randf(0, window.innerWidth), | |
ax: randf(g.amin, g.amax), | |
ay: randf(g.amin, g.amax), | |
ar: randf(g.ramin, g.ramax), | |
px: randf(g.pmin, g.pmax) * randSign(), | |
py: randf(g.pmin, g.pmax) * randSign(), | |
pr: randf(g.rpmin, g.rpmax) * randSign() | |
} | |
); | |
l = els[i]; | |
l.el.style.position = "absolute"; | |
l.el.style.zIndex = 9e10 * randSign(); | |
l.el.style.top = l.t + "px"; | |
l.el.style.left = l.l + "px"; | |
l.el.style.width = | |
l.el.style.height = randf(1, 40) + "%"; | |
} | |
} | |
function startLoop() { | |
for(var i = 0; i < els.length; i++) { | |
var l = els[i]; | |
l.el.style.top = l.t + sin(l.ay, l.py) + "px"; | |
l.el.style.left = l.l + sin(l.ax, l.px) + "px"; | |
l.el.style.transform = "rotate(" + sin(l.ar, l.pr) + "deg)"; | |
} | |
g.time += 0.03; | |
window.requestAnimationFrame(startLoop); | |
} | |
generateVariables(); | |
startLoop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment