var b=document.body.children[0],Z=50;with(b)var c=width=innerWidth,f=height=innerHeight,k=getContext("2d"),l=c/2,m=f/2,n=Math,p=n.max,q=n.random,r=parseInt,s=n.sin,t=n.cos,u=0,w=s(.8),x=t(.8),y=0,z=rz=.01,B=200,C=500;function D(a,d,g){var e=s(y),i=t(y),j=x*g-w*(i*d-e*a);return[l-(e*d+i*a)*B/j,m+(w*g+x*(i*d-e*a))*B/j,j]} function E(a){var d=a[0],g=a[1],e=a[2],i=d+a[3],j=g+a[4],o=D(d,g,e),v=true;with(k){fillStyle=strokeStyle=a[5];[o,D(i,g,e),D(i,j,e),D(d,j,e),o].every(function(h,A){if(h[0]<0||h[0]>c||h[1]>f)v=false;A===0?beginPath(p(h[0],0),p(h[1],0)):lineTo(p(h[0],0),p(h[1],0));return v||A!=0});fill();if(a[2]>-C){moveTo(o[0],o[1]);a=D(d,g,-C);lineTo(a[0],a[1]);stroke()}}return v}var F=[];setInterval(function(){k.fillStyle="#eee";k.fillRect(0,0,c,f);for(F=F.filter(function(a){a[1]-=a[6];a[2]+=a[7];if(a[2]<=-C)a[7]=0;return E(a)});F.length<B;)F.push([-16*C+q()*32*C,4*C-q()*Z,-B+q()*-C,Z+q()*B,Z+q()*B,"rgb("+r(q()*B)+","+r(q()*B)+","+r(q()*B)+")",Z+q()*Z,-10+q()*-Z]);y+=z;z=y>.3?-rz:y<-.3?rz:z;u+=20},Z);
var canvas = document.body.children[0];
/** @const **/
with (canvas) {
var WIDTH = width = innerWidth;
/** @const **/
var HEIGHT = height = innerHeight;
var ctx = getContext('2d');
var ex = WIDTH / 2;
var ey = HEIGHT / 2;
var M = Math;
var max = M.max;
var rand = M.random;
var pint = parseInt;
var sin = M.sin;
var cos = M.cos;
// camera, position
var cy = 0;
// camera rotation
var ox = .8;
var sinox = sin(ox);
var cosox = cos(ox);
var oz = 0;
var rotZDir = rz = .01;
var twohundred = 200;
var fivehundred = 500;
}
function worldToScreen(ax, ay, az) {
// camera rotation
var sinoz = sin(oz);
var cosoz = cos(oz);
var dx = (sinoz * ay + cosoz * ax);
var dy = sinox * az + cosox * (cosoz * ay - sinoz * ax);
var dz = cosox * az - sinox * (cosoz * ay - sinoz * ax);
return [
ex - (dx * twohundred / dz),
ey + (dy * twohundred / dz),
dz
]
};
function drawBox(box) {
var x = box[0];
var y = box[1];
var z = box[2];
var w = box[3];
var h = box[4];
var xw = x + w;
var yh = y+h;
var p0 = worldToScreen(x, y, z);
var keepIt = true;
with (ctx) {
fillStyle = strokeStyle = box[5];
[p0,
worldToScreen(xw, y, z),
worldToScreen(xw, yh, z),
worldToScreen(x, yh, z),
p0
].every(function(p, i) {
if (p[0] < 0 || p[0] > WIDTH || p[1] > HEIGHT) {
keepIt = false;
}
if (i === 0) {
beginPath(max(p[0],0), max(p[1],0));
} else {
lineTo(max(p[0],0), max(p[1],0));
}
return (keepIt || i != 0);
});
fill();
if (box[2] > -fivehundred) {
moveTo(p0[0], p0[1]);
var groundPoint = worldToScreen(x, y, -fivehundred);
lineTo(groundPoint[0], groundPoint[1]);
stroke();
}
}
return keepIt;
}
var boxes = [];
setInterval(function() {
ctx.fillStyle = '#eee';
ctx.fillRect(0,0,WIDTH,HEIGHT);
boxes = boxes.filter(function(box) {
box[1] -= box[6];
box[2] += box[7];
if (box[2] <= -fivehundred) box[7] = 0;
return drawBox(box);
});
while(boxes.length<twohundred) {
// 0, 1, 2, 3, 4, 5, 6, 7
// x, y, z, w, h, color, speed y, speed z
boxes.push([
-16*fivehundred + (rand() * 32*fivehundred),
3*fivehundred - rand() * 50,
-twohundred + rand() * -fivehundred,
50 + rand() * twohundred,
50 + rand() * twohundred,
"rgb(" + pint(rand() * twohundred) + "," + pint(rand() * twohundred) + "," + pint(rand() * twohundred) + ")",
50 + rand() * 50,
-10 + rand() * -50
]);
}
oz += rotZDir;
rotZDir = oz > .2 ? -rz :
oz < -.2 ? rz : rotZDir;
cy += 20;
}, 100);