Last active
January 25, 2017 13:18
-
-
Save 9999years/4c4b38b91259b327141670a3e62236ed 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
//see https://gist.github.com/9999years/8fd0184530fcbbe494ffc306bab8654b for more verbosity | |
//kinda golfed (1507 bytes) | |
var els = [], g = { img: document.getElementsByTagName("img"), time: 0, amt: 20, | |
amin: 5 /* amp */, amax: 10, ramin: 1 /* rot amp */, ramax: 50, pmin: 1 /* perio | |
d */, 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 randEl(arr) { return arr[Math.floor(Math | |
.random()*arr.length)]; } function generateVariables() { for(var i = els.length; | |
i < g.amt; i++) {els.push({el: document.body.appendChild(randEl(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 = "ab" | |
+ "solute"; l.el.style.zIndex = 9*1e10 * randSign(); l.el.style.top = l.t + "px" | |
;l.el.style.left = l.l + "px"; l.el.style.width = randf(1, 40) + "%"; l.el.style | |
.height = "initial"; } } function startLoop() { for(var i = 0; i < els.length; i | |
+= 1) { 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(); | |
//more golfed (796 bytes) | |
var o=[],l,x,S="style",i,d=document,w=window,M=Math,P="px",g={m:d. | |
getElementsByTagName("img")[0],p:0,j:20,k:5,a:10,b:1,c:50,d:1,e:10,f:1,h:50},r=( | |
a,i)=>M.random()*(a-i)+i,n=()=>2*M.round(r(0,1))-1,s=(q,r)=>q*M.sin(g.p*2*M.PI/r | |
),G=()=>{z=o.length;for(i=z;i<z+g.j;i++){o.push({el:d.body.appendChild(g.m. | |
cloneNode()),t:r(0,d.body.scrollHeight),l:r(0,w.innerWidth),a:r(g.k,g.a),b:r(g.k | |
,g.a),c:r(g.b,g.c),d:r(g.d,g.e)*n(),e:r(g.d,g.e)*n(),g:r(g.f,g.h) *n()});l=o[i]; | |
l.el[S].position="absolute";l.el[S].zIndex=9e10*n();l.el[S].top=l.t+P;l.el[S]. | |
left=l.l+P;l.el[S].width=l.el[S].height=r(1,40)+"%";}},Z=()=>{for(i=0;i<o.length | |
;i++){l=o[i];l.el[S].top=l.t+s(l.b,l.e)+P;l.el[S].left=l.l+s(l.a,l.d)+P;l.el[S]. | |
transform="rotate("+s(l.c,l.g)+"deg)";}g.p+=0.03;w.requestAnimationFrame(Z);}; | |
G();Z(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment