-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp2.html
92 lines (77 loc) · 2.37 KB
/
app2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="author" content="Olivier BOES">
<title>Dodecahedron</title>
<style>
body {
font-family: Monospace;
background-color: #000000;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<script src="./Three.js"></script>
<script src="./TrackballControls.js"></script>
<script src="./Chain.js"></script>
<script>
var renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 1000 );
camera.position.set( 100, 1, 2 );
camera.up.set( 0, 0, 1 );
var controls = new THREE.TrackballControls( camera );
var scene = new THREE.Scene();
var ceilingLight = new THREE.SpotLight( 0xffffff );
ceilingLight.position.set( 0, 0, 40 );
scene.add( ceilingLight );
var cameraLight = new THREE.DirectionalLight( 0xffffff );
cameraLight.position = camera.position;
scene.add( cameraLight );
var len = 5;
var theta = 72; // 360° / 5
var delta = 116.56505; // arccos( -1/sqrt(5) )
var param = [
[ len, theta, 0 ],
[ len, theta, 0 ],
[ len, theta, 0 ],
[ len, theta, 0 ],
[ len, theta, delta ],
[ len, theta, 0 ],
[ len, theta, 0 ],
[ len, theta, -delta ],
[ len, theta, delta ],
[ len, theta, -delta ],
[ len, theta, delta ],
[ len, theta, -delta ],
[ len, theta, delta ],
[ len, theta, -delta ],
[ len, theta, 0 ],
[ len, theta, 0 ],
[ len, theta, delta ],
[ len, theta, 0 ],
[ len, theta, 0 ]
];
var chain = new Chain();
chain.update( params2points( param ) );
scene.add( chain );
function animate() {
requestAnimationFrame( animate );
controls.update();
for ( var i = 0 ; i < param.length ; i++ ) {
if ( ( theta-1 < param[i][1] && param[i][1] < theta+1 )
|| ( 360-theta-1 < param[i][1] && param[i][1] < 360-theta+1 ) ) param[i][1] += 0.01
else param[i][1] += 1;
param[i][1] = param[i][1] % 360;
}
chain.update( params2points( param ) );
renderer.render( scene, camera );
};
animate();
</script>
</body>
</html>