forked from asarilar/nyancat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
112 lines (101 loc) · 4.23 KB
/
index.html
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
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<script src='vendor/three.js/build/three.js'></script>
<script src="vendor/require.js/require.js"></script>
<script src="vendor/three.js/examples/js/Detector.js"></script>
<script src="vendor/threex.windowresize.js"></script>
<link rel="stylesheet" href="style.css">
<body style='margin: 0px; overflow: hidden;'><script>
require([
'bower_components/threex.nyancat/package.require.js',
], function(){
// detect WebGL
if( !Detector.webgl ){
Detector.addGetWebGLMessage();
throw 'WebGL Not Available'
}
// setup webgl renderer full page
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// setup a scene and camera
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 1000);
camera.position.z = 3;
// declare the rendering loop
var onRenderFcts= [];
// handle window resize events
var winResize = new THREEx.WindowResize(renderer, camera)
//////////////////////////////////////////////////////////////////////////////////
// add nyanCat object to scene //
//////////////////////////////////////////////////////////////////////////////////
var nyanCat = new THREEx.NyanCat();
nyanCat.container.scale.multiplyScalar(2/30);
scene.add( nyanCat.container );
// updateFcts.push(function(delta, now){
// if( paused ) return
// nyanCat.update(delta, now)
// });
//////////////////////////////////////////////////////////////////////////////////
// default 3 points lightning //
//////////////////////////////////////////////////////////////////////////////////
var ambientLight= new THREE.AmbientLight( 0x020202 )
scene.add( ambientLight)
var frontLight = new THREE.DirectionalLight('white', 1)
frontLight.position.set(0.5, 0.5, 2)
scene.add( frontLight )
var backLight = new THREE.DirectionalLight('white', 0.75)
backLight.position.set(-0.5, -0.5, -2)
scene.add( backLight )
//////////////////////////////////////////////////////////////////////////////////
// add an object and make it move //
//////////////////////////////////////////////////////////////////////////////////
// var geometry = new THREE.CubeGeometry( 1, 1, 1);
// var material = new THREE.MeshPhongMaterial();
// var mesh = new THREE.Mesh( geometry, material );
// scene.add( mesh );
// onRenderFcts.push(function(delta, now){
// mesh.rotateX(0.5 * delta);
// mesh.rotateY(2.0 * delta);
// })
//////////////////////////////////////////////////////////////////////////////////
// Camera Controls //
//////////////////////////////////////////////////////////////////////////////////
var mouse = {x : 0, y : 0}
document.addEventListener('mousemove', function(event){
mouse.x = (event.clientX / window.innerWidth ) - 0.5
mouse.y = (event.clientY / window.innerHeight) - 0.5
}, false)
onRenderFcts.push(function(delta, now){
camera.position.x += (mouse.x*5 - camera.position.x) * (delta*3)
camera.position.y += (mouse.y*5 - camera.position.y) * (delta*3)
camera.lookAt( scene.position )
})
//////////////////////////////////////////////////////////////////////////////////
// render the scene //
//////////////////////////////////////////////////////////////////////////////////
onRenderFcts.push(function(){
renderer.render( scene, camera );
})
//////////////////////////////////////////////////////////////////////////////////
// Rendering Loop runner //
//////////////////////////////////////////////////////////////////////////////////
var lastTimeMsec= null
requestAnimationFrame(function animate(nowMsec){
// keep looping
requestAnimationFrame( animate );
// measure time
lastTimeMsec = lastTimeMsec || nowMsec-1000/60
var deltaMsec = Math.min(200, nowMsec - lastTimeMsec)
lastTimeMsec = nowMsec
// call each update function
onRenderFcts.forEach(function(onRenderFct){
onRenderFct(deltaMsec/1000, nowMsec/1000)
})
})
})
</script>
<audio id="nyan-cat-song" src="https://github.com/ShaAlexander/nyancat/blob/4c1340272fd3c30e8ab3812db748d45e85786cfb/Nyan%20Cat%20Sound%20Effect.mp3" loop></audio>
<button id="play-button">Play Nyan Cat Song</button>
<script src="script.js"></script>
</body>
</body>