// bind to window onload event
window.addEventListener('load', onloadHandler, false);
 
function onloadHandler()
{
   // get the canvas DOM element
   var canvas = document.getElementById('cflogo');
 
   // bind a K3D Controller object to the canvas
   // - it is responsible for managing the K3D objects displayed within it
   var k3d = new K3D.Controller(canvas);
   // request 60 frames per second animation from the controller
   k3d.fps = 30;
 
   // create a K3D object for rendering
   var obj = new K3D.K3DObject();
   with (obj)
   {
      color = [34,34,34];      // colour used for wireframe edges and depthcues
      drawmode = "wireframe"; // one of "point", "wireframe", "solid"
      shademode = "plain";    // one of "plain", "depthcue",
                              //   "lightsource" (solid drawing mode only)
      addphi = 0.5;           // 1 degree of rotation around Y axis per frame
      scale = 30;             // make fifty times bigger
      init(
         // describe the eight points of a simple unit cube
         [{x:-1,y:1,z:-1}, {x:1,y:1,z:-1}, {x:1,y:-1,z:-1}, {x:-1,y:-1,z:-1},
          {x:-1,y:1,z:1}, {x:1,y:1,z:1}, {x:1,y:-1,z:1}, {x:-1,y:-1,z:1},
		  {x:0.5,y:1,z:-0.5}, {x:-1,y:0,z:-0.5}, {x:0.5,y:-1,z:-0.5}, 
		  {x:0,y:0.66,z:0.5}, {x:0,y:-0.66,z:0.5}, {x:1,y:0.66,z:0.5}, {x:0,y:0.5,z:0.5}, {x:0.5,y:0.5,z:0.5},],
         // describe the twelve edges of the cube
         [{a:0,b:1}, {a:1,b:2}, {a:2,b:3}, {a:3,b:0}, {a:4,b:5}, {a:5,b:6},
          {a:6,b:7}, {a:7,b:4}, {a:0,b:4}, {a:1,b:5}, {a:2,b:6}, {a:3,b:7}, {a:8,b:9}, {a:9,b:10},
		  {a:11,b:12}, {a:11,b:13}, {a:14,b:15}],
         // describe the six polygon faces of the cube
         [{color:[255,0,0],vertices:[0,1,2,3]}, {color:[0,255,0],vertices:[0,4,5,1]},
          {color:[0,0,255],vertices:[1,5,6,2]}, {color:[255,255,0],vertices:[2,6,7,3]},
          {color:[0,255,255],vertices:[3,7,4,0]}, {color:[255,0,255],vertices:[7,6,5,4]}]
      );
   }
 
   // add the object to the controller
   k3d.addK3DObject(obj);
 
   // begin the rendering and animation immediately
   k3d.paused = false;
   k3d.frame();
}
