E=document.body.children[0];M=Math;c=78;p=[];while(c--)p[c]=c/10;function S(a,b){C=[];V=0;for(y=0;y<a.length;){C[V]=[];for(x=0;x<b;){W=a.charCodeAt(y++)-33;C[V][x++]=b<4?p[W]-4:W}V++}return C}h=S("====IQ=Id:Id:IU=IQ:IU6IU2IQJI`LIdCIdAI`LIYJI\\AI\\CIYJIQLIUCIUAIQTIQTIdPI`PIQ[IQ[IdWIdWIQbId_Id[I^[IY_IQbIQ]I\\[IYHIULIULIYHIY2IQ6IU6IY2IYAI\\EI\\EI`AI`0<Gd<GdAH0AH05Ed5Ed:F0:F0.Cd.Cd3D03D0'Ad'Ad,C0,CgnIgn:-n:-nI-G:-GI-!:-!@gGIg!@g!:gG:dnndIndIIdnI0II0In0nn0nI0In0IIdIIdIn",3);n=S("MJKL$%\"#()&'HIFGPQNO,-*+1./052348967<=:;@A>?DEBCRSTUVWXYZ[\\]^_`abcdefgedhigfjklmbjmcgjbehlkinopqrstuontsxyvw",4);setInterval("w=innerWidth-24;j=innerHeight-24;E.width=w;E.height=j;with(E.getContext('2d')){H=M.sin(c);O=M.cos(c+=.02);clearRect(0,0,w,j);beginPath();for(g in n){if(g==12)fill();for(u in f=n[g]){l=h[f[u]];Z=-l[0]*O*O-l[1]*H*O+l[2]*H+13;X=j*(-l[0]*H+l[1]*O)/Z+w/2;Y=j*(-l[0]*H*O-l[1]*H*H-l[2]*O)/Z+j/2;if(u==0)moveTo(X,Y);lineTo(X,Y)}closePath()}stroke()}",30)
/*
A rotating 3D computer wireframe v2.
Luis Gonzalez - lobster@luis.net
released for http://www.js1k.com
Features:
- CPU, Keyboard and Monitor
- 3D Text that displays solid filled "JS1K" on the monitor
- browser scaling and auto-centering
- works in firefox, chrome, safari and opera
3D Model created in 3D Studio Max 9 then exported to wavefront OBJ format (quads).
The 3D model was hand tweaked to occupy as many whole numbers as possible for its points.
then manually compressed using ASCII table reference
download 3D computer model here:
http://luis.net/projects/1k/3d/computer.obj (Wavefront OBJ quads)
screenshot:
http://www.flickr.com/photos/luis2048/4930263977/
http://luis.net/projects/1k/3d/screenshot.png
*/
// set it up
E=document.body.children[0];
M=Math; // its math time
c=78; // our global counter used for rotation
p=[];while(c--)p[c]=c/10; // vertex data [-4, -3.9, 3.8, 3.7.....3.8,3.9,4]
// decompress data points in either 3(verticies - [[X1,Y1,Z1]]) or 4(faces - [[1,2,3,4]]) using ASCII table charcodes
function S(a,b){
C=[]; // array we are building
V=0;
for(y=0;y<a.length;){ // loop through entire string "000I@H1@H1>9"
C[V]=[]; // create a sub array to contain points(4) or vertice(3) defined by b
for(x=0;x<b;){ // loop either 3 or 4 times
W=a.charCodeAt(y++)-33; // G = (charcode 71)-48 = (23 array index) = "-10.2" or 23
C[V][x++]=b<4?p[W]-4:W; // append either points to new array or index position
}
V++;
}
return C; // return our newly assembled array
}
// verticies (X,Y,Z)
// returns the following format: h=[[-10,-7.1,-.7],[7,-7.1,-.7],[7,-5.5,-.3],[-10,-5.5,-.3],[-10,-9.5,-1.3]];
h=S("====IQ=Id:Id:IU=IQ:IU6IU2IQJI`LIdCIdAI`LIYJI\\AI\\CIYJIQLIUCIUAIQTIQTIdPI`PIQ[IQ[IdWIdWIQbId_Id[I^[IY_IQbIQ]I\\[IYHIULIULIYHIY2IQ6IU6IY2IYAI\\EI\\EI`AI`0<Gd<GdAH0AH05Ed5Ed:F0:F0.Cd.Cd3D03D0'Ad'Ad,C0,CgnIgn:-n:-nI-G:-GI-!:-!@gGIg!@g!:gG:dnndIndIIdnI0II0In0nn0nI0In0IIdIIdIn",3);
// faces - connect four vertices to make a quad
// returns the following format: n=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]];
// J = MJKL$%\"#()&'
// S = HIFGPQNO,-*+1./05234
// 1 = 8967
// K = <=:;@A>?DEBC
n=S("MJKL$%\"#()&'HIFGPQNO,-*+1./052348967<=:;@A>?DEBCRSTUVWXYZ[\\]^_`abcdefgedhigfjklmbjmcgjbehlkinopqrstuontsxyvw",4);
// main animation loop
setInterval(
function(){
w=innerWidth-24; // get browser dimensions - 24 margin to prevent scrollbars
j=innerHeight-24;
E.width=w; // set canvas to occupy full screen
E.height=j; // ditto for height
with(E.getContext('2d'))
{
H=M.sin(c); // im spinning
O=M.cos(c+=.02); // counter spin and increment c for animation
clearRect(0,0,w,j); // clear the screen
// our tiny 3D engine
beginPath();
for(g in n)
{
if (g==12)fill();
// loop through each face(4)
for(u in f=n[g])
{
l=h[f[u]]; // connect our verticies to form a quad 1-2 then 2-3 then 3-0 then 0-1
Z=-l[0]*O*O-l[1]*H*O+l[2]*H+13;
X=j*(-l[0]*H+l[1]*O)/Z+w/2;
Y=j*(-l[0]*H*O-l[1]*H*H-l[2]*O)/Z+j/2;
// draw our 3D line in 2D space
if (u==0)
moveTo(X,Y);
lineTo(X,Y);
}
closePath();
}
stroke();
}
},30)