A=800;function i(a,b){return j.pow(-1,j.floor(a/b))}function D(s){c.strokeStyle=s}function n(a,b,g){e=o(b);$=u(b),f=o(a);x=u(a);for(h=[],d=0;d<8;++d){q=i(d+1,2),r=i(d,4),v=i(d,2),w=v*f-r*$*x+q*x*e-4;h.push([400+g*(q*$+r*e)/w,400+g*(v*x+r*$*f-q*e*f)/w])}c.beginPath();for(d=0;d<17;++d)c.lineTo.apply(c,h["01537123045674260"[d]]);c.stroke()}function s(a,b,g){for(B=o(b+a)/15,C=0;C<4;++C){k=i(C,1);n(a+i(C,2)*B,b+k*B,g);n(a+k*B,b,g);n(a,b+k*B,g)}}k=document,x=k.body.style;x.textAlign="center";x.background="#57a";k=k.getElementById("c");k.width=k.height=A;c=k.getContext("2d"),l=0,y=0,m=0,z=0,j=Math,t=j.random,o=j.sin,u=j.cos;window.setInterval(function(){c.clearRect(0,0,A,A);a=(t()-0.5)/20;if(t()>0.97)y=a;if(t()>0.97)z=a;l+=y;m+=z;D("#89b");for(a=1;a<30;++a)for(b=1;b<30;++b)c.strokeRect(a*25,b*25,25,25);D("#dde");c.strokeRect(37,37,725,725);s(m,l,200);D("#f70");s(m,l,400);D("#fff");s(m,l,A)},40)
var win = window;
win.onload = function() {
var doc = document;
var style = document.body.style;
style.textAlign = "center";
style.background = "#57a";
var canvas = doc.getElementById('c');
canvas.width = canvas.height = 800;
var context = canvas.getContext('2d');
var phi = 0;
var dphi = 0;
var theta = 0;
var dtheta = 0;
var m = Math;
var random = m.random;
var sin = m.sin;
var cos = m.cos;
function recurrence(index, width) {
return m.pow(-1, m.floor(index / width));
}
function drawCube(theta, phi, kC) {
var sPhi = sin(phi);
var cPhi = cos(phi);
var sTheta = sin(theta);
var cTheta = cos(theta);
var kA = 400;
var kB = 25 / 6;
var points = new Array();
for(var i = 0; i < 8; ++i) {
var rA = recurrence(i + 1, 2);
var rB = recurrence(i, 4);
var rC = recurrence(i, 2);
var w = rC * sTheta - rB * cPhi * cTheta + rA * cTheta * sPhi - kB;
points.push([kA + kC * (rA * cPhi + rB * sPhi) / w,
kA + kC * (rC * cTheta + rB * cPhi * sTheta - rA * sPhi * sTheta) / w]);
}
context.beginPath();
var path = "01537123045674260";
for (var i = 0; i < 17; ++i) {
var index = path[i];
context.lineTo.apply(context, points[index]);
}
context.stroke();
}
function drawCubes(theta, phi, kC) {
var rA = sin(phi + theta) * kC / 24000;
for(var i = 0; i < 4; ++i) {
var rB = recurrence(i, 2);
var rC = recurrence(i, 1);
//setStrokeStyle("#fdd");
drawCube(theta + rB * rA, phi + rC * rA, kC);
//setStrokeStyle("#d77");
drawCube(theta + rC * rA, phi, kC);
//setStrokeStyle("#fff");
drawCube(theta, phi + rC * rA, kC);
}
}
function drawBackground() {
context.strokeStyle = "#89b";
for(var i = 1; i < 31; ++i)
for(var j = 1; j < 31; ++j)
context.strokeRect(i * 25, j * 25, 25, 25);
context.strokeStyle ="#dde";
context.strokeRect(37, 37, 725, 725);
}
win.setInterval(function() {
context.clearRect(0, 0, 800, 800);
var newDelta = (random() - 0.5) / 20;
if(random() > 0.97)
dphi = newDelta;
if(random() > 0.97)
dtheta = newDelta;
phi += dphi;
theta += dtheta;
drawBackground();
drawCubes(theta, phi, 200);
context.strokeStyle ="#f70"
drawCubes(theta, phi, 400);
context.strokeStyle ="#fff"
drawCubes(theta, phi, 800);
}, 40);
};