-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.js
More file actions
102 lines (92 loc) · 2.87 KB
/
bootstrap.js
File metadata and controls
102 lines (92 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
FRAME_LENGTH = 882;
t = 0;
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 0);
};
})();
window.makeFullscreen = function(elem) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
};
function loop(){
t = music.currentTime*1000;
dt = (t-old_time);
old_time = music.currentTime;
while(dt> FRAME_LENGTH){
update();
dt-= FRAME_LENGTH;
}
render();
if (!music.ended)
requestAnimFrame(loop);
}
function start(){
old_time = 0;
dt = 0;
init();
}
function setLoadingBar(completed,fn){
tdx.fillStyle = "white";
tdx.fillRect(0,0,16*GU,9*GU);
tdx.fillStyle = "black";
tdx.fillRect(GU, 4.25*GU,14*GU*completed ,GU*0.5);
console.log("LOADING",completed);
setTimeout(function(){
fn();
if(completed == 1){
tdx.clearRect(0,0,16*GU,9*GU);
requestAnimFrame(loop);
music.play();
}
},0);
}
function bootstrap(){
//makeFullscreen(document.body);
document.addEventListener("keydown",function(e){
if(e.keyCode == /*ESC*/ 27){
window.open('', '_self', ''); //bug fix
window.close();
}
});
renderer = new THREE.WebGLRenderer({ maxLights: 10,antialias:true, clearColor:0x191919, clearAlpha:1});
renderer.sortObjects = false;
twoDCanvas = document.createElement("canvas");
twoDCanvas.style.position = "absolute";
twoDCanvas.style.left = "0";
twoDCanvas.style.zIndex = "8999";
twoDCanvas.style.background = "transparent";
tdx = twoDCanvas.getContext("2d");
resize();
Math.seedrandom('kinkisawesomebitchyo');
document.body.appendChild(renderer.domElement);
document.body.appendChild(twoDCanvas);
var file_format = Modernizr.audio.ogg ? 'ogg' : 'mp3';
music = new Audio( "audio/soundtrack." + file_format );
setTimeout(start,0);
}
function resize(){
if(window.innerWidth/window.innerHeight > 16/9){
GU = (window.innerHeight/9);
}else{
GU = (window.innerWidth/16);
}
renderer.setSize(16*GU, 9*GU);
renderer.domElement.style.margin = ((window.innerHeight - 9*GU) /2)+"px 0 0 "+((window.innerWidth-16*GU)/2)+"px";
twoDCanvas.width = 16*GU;
twoDCanvas.height = 9*GU;
twoDCanvas.style.margin = ((window.innerHeight - 9*GU) /2)+"px 0 0 "+((window.innerWidth-16*GU)/2)+"px";
tdx.font = (GU/3)+"pt BebasNeue";
tdx.textBaseline = "top";
}
window.onresize = resize;