for(var vc=[-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1],ps=[],ac=[0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7,0,2,4,6,0,7,1,6,0,5,3,6],as=[],i=0,j=0;i<72;i+=2,j+=3){if(j<24){var o={x:100*vc[j],y:100*vc[j+1],z:100*vc[j+2],f:!j,d:.995};o.oldX=o.x,o.oldY=o.y,o.oldZ=o.z,ps.push(o)}36<=i&&as.push({p1:ps[ac[i-36]],p2:ps[ac[i-35]],l:60<=i?141:100})}function td(p,o,i){var d=5/(5-i/100);return{x:p*d+a.width/2,y:o*d+a.height/2}}!function p(){a.width=a.width;for(var o=as.length,i=0;i<2*o;i++){var d=ps[i],t=as[i-o];if(d){var r=(d.x-d.oldX)*d.d,s=(d.y-d.oldY)*d.d,x=(d.z-d.oldZ)*d.d;d.oldX=d.x,d.oldY=d.y,d.oldZ=d.z,d.x+=r,d.y+=s+(d.f?0:.3),d.z+=x}if(t){var y=t.p1.x-t.p2.x,l=t.p1.y-t.p2.y,v=t.p1.z-t.p2.z,f=Math.sqrt(y*y+l*l+v*v),z=(t.l-f)/f/2,e=-y*z,h=-l*z,n=-v*z;t.p1.f||(t.p1.x-=e,t.p1.y-=h,t.p1.z-=n),t.p2.f||(t.p2.x+=e,t.p2.y+=h,t.p2.z+=n);var j=td(t.p1.x,t.p1.y,t.p1.z),u=td(t.p2.x,t.p2.y,t.p2.z);c.beginPath(),c.moveTo(j.x,j.y),c.lineTo(u.x,u.y),c.stroke()}}requestAnimationFrame(p)}();
/*var a = document.getElementById("canvas");
a.width = innerWidth;
a.height = innerHeight;
var c = a.getContext("2d");*/ //Not needed
var vc = [-1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1];
var ps = [];
var ac = [0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7, 0, 2, 4, 6, 0, 7, 1, 6, 0, 5, 3, 6];
var as = [];
for (var i = 0, j = 0; i < 72; i += 2, j += 3) {
if (j < 24) {
var o = {x: vc[j] * 100, y: vc[j + 1] * 100, z: vc[j + 2] * 100, f: !j, d: .995};
o.oldX = o.x, o.oldY = o.y, o.oldZ = o.z;
ps.push(o);
}
if (i >= 36)
as.push({p1: ps[ac[i - 36]], p2: ps[ac[i - 35]], l: i >= 60 ? 141 : 100});
}
/*setTimeout(function() {
ps[0].fixed = false;
}, 2000);*/
(function loop() {
a.width = a.width;
var l = as.length;
for (var i = 0; i < l * 2; i++) {
var p = ps[i];
var w = as[i - l];
if (p) {
var vx = (p.x - p.oldX) * p.d;
var vy = (p.y - p.oldY) * p.d;
var vz = (p.z - p.oldZ) * p.d;
p.oldX = p.x;
p.oldY = p.y;
p.oldZ = p.z;
p.x += vx;
p.y += vy + (p.f ? 0 : .3);
p.z += vz;
/*if (p.y > 200)
p.y = 200;*/
}
if (w) {
var x = w.p1.x - w.p2.x;
var y = w.p1.y - w.p2.y;
var z = w.p1.z - w.p2.z;
var distance = Math.sqrt(x * x + y * y + z * z);
var percent = (w.l - distance) / distance / 2;
var oX = -x * percent;
var oY = -y * percent;
var oZ = -z * percent;
if (!w.p1.f)
w.p1.x -= oX, w.p1.y -= oY, w.p1.z -= oZ;
if (!w.p2.f)
w.p2.x += oX, w.p2.y += oY, w.p2.z += oZ;
var cp1 = td(w.p1.x, w.p1.y, w.p1.z);
var cp2 = td(w.p2.x, w.p2.y, w.p2.z);
c.beginPath();
c.moveTo(cp1.x, cp1.y);
c.lineTo(cp2.x, cp2.y);
c.stroke();
}
}
requestAnimationFrame(loop);
})();
function td(x, y, z) {
var Z = 5 / (5 - z / 100);
return {x: x * Z + a.width / 2, y: y * Z + a.height / 2};
}