4
* Copyright (C) Kevin Roast 2010
5
* http://www.kevs3d.co.uk/dev
6
* email: kevtoast at yahoo.com
9
* I place this code in the public domain - because it's not rocket science
10
* and it won't make me any money, so do whatever you want with it, go crazy
13
// bind to window events
14
window.addEventListener('load', onloadHandler, false);
17
* Window onload handler
19
function onloadHandler()
24
// create canvas element for the k3d render output
25
var canvas = document.createElement('canvas');
27
canvas.width = CANVASSIZE;
28
canvas.height = CANVASSIZE;
29
canvas.title = "Kevs 3D";
30
canvas.style.position = "absolute";
31
canvas.style.zIndex = 100;
32
canvas.style.cursor = "pointer";
33
document.body.appendChild(canvas);
34
canvas.style.left = canvas.style.top = OFFSET + "px";
36
// track scroll position to update widget pos
37
var destinationY = positionY = OFFSET;
39
// bind scrolling event listener - needs reference to the canvas element
40
window.addEventListener('scroll', function onscroll()
42
destinationY = window.pageYOffset + OFFSET;
45
// create k3d controller and bind to the canvas
46
var k3d = new K3D.Controller(canvas, true);
50
var obj = new K3D.K3DObject();
53
var t = (1+Math.sqrt(5))/2,
54
tau = t/Math.sqrt(1+t*t),
55
one = 1/Math.sqrt(1+t*t);
59
shademode = "lightsource";
61
addgamma = 1; addtheta = -0.5; addphi = 0.8;
64
[{x:tau,y:one,z:0}, {x:-tau,y:one,z:0}, {x:-tau,y:-one,z:0}, {x:tau,y:-one,z:0}, {x:one,y:0,z:tau}, {x:one,y:0,z:-tau}, {x:-one,y:0,z:-tau}, {x:-one,y:0,z:tau}, {x:0,y:tau,z:one}, {x:0,y:-tau,z:one}, {x:0,y:-tau,z:-one}, {x:0,y:tau,z:-one}],
65
[{a:4,b:8}, {a:8,b:7}, {a:7,b:4}, {a:7,b:9}, {a:9,b:4}, {a:5,b:6}, {a:6,b:11}, {a:11,b:5}, {a:5,b:10}, {a:10,b:6}, {a:0,b:4}, {a:4,b:3}, {a:3,b:0}, {a:3,b:5}, {a:5,b:0}, {a:2,b:7}, {a:7,b:1}, {a:1,b:2}, {a:1,b:6}, {a:6,b:2}, {a:8,b:0}, {a:0,b:11}, {a:11,b:8}, {a:11,b:1}, {a:1,b:8}, {a:9,b:10}, {a:10,b:3}, {a:3,b:9}, {a:9,b:2}, {a:2,b:10} ],
66
[{color:[255,255,255],vertices:[4, 8, 7]}, {color:[255,255,0],vertices:[4, 7, 9]}, {color:[0,255,255],vertices:[5, 6, 11]}, {color:[128,0,255],vertices:[5, 10, 6]}, {color:[0,0,255],vertices:[0, 4, 3]}, {color:[255,0,0],vertices:[0, 3, 5]}, {color:[0,255,0],vertices:[2, 7, 1]}, {color:[255,0,0],vertices:[2, 1, 6]}, {color:[128,128,128],vertices:[8, 0, 11]}, {color:[255,128,0],vertices:[8, 11, 1]}, {color:[0,128,255],vertices:[9, 10, 3]}, {color:[255,0,128],vertices:[9, 2, 10]}, {color:[0,128,255],vertices:[8, 4, 0]}, {color:[128,255,0],vertices:[11, 0, 5]}, {color:[0,255,128],vertices:[4, 9, 3]}, {color:[128,255,255],vertices:[5, 3, 10]}, {color:[255,128,255],vertices:[7, 8, 1]}, {color:[128,0,255],vertices:[6, 1, 11]}, {color:[0,255,128],vertices:[7, 2, 9]}, {color:[255,0,255],vertices:[6, 10, 2]}]
69
k3d.addK3DObject(obj);
71
// canvas position state
72
k3d.callback = function()
74
if (positionY != destinationY)
76
// track towards new destination Y position
77
positionY += (destinationY - positionY) / OFFSET;
78
canvas.style.top = Math.floor(positionY) + "px";
82
canvas.addEventListener('click', function click() {
83
window.location.href = INDEX;
b'\\ No newline at end of file'