-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
230 lines (193 loc) · 8.69 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<html>
<head>
<title>The Truth</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script>
// Add the scene.
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Fix the viewport / aspect ratio.
window.addEventListener('resize', function() {
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
// Create perspective, or "controls" for the shape.
controls = new THREE.OrbitControls(camera, renderer.domElement);
// Create a skybox.
var cGeometry = new THREE.CubeGeometry(400, 400, 400);
var cubeMaterials =
[
new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('https://i.imgur.com/ozprQHK.png'), side: THREE.DoubleSide}),
new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('https://i.imgur.com/P7z88hA.png'), side: THREE.DoubleSide}),
new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('https://i.imgur.com/vIvLCtY.png'), side: THREE.DoubleSide}),
new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('https://i.imgur.com/zpyUh80.png'), side: THREE.DoubleSide}),
new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('https://i.imgur.com/DL0x11e.png'), side: THREE.DoubleSide}),
new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('https://i.imgur.com/gbBzQZZ.png'), side: THREE.DoubleSide})
];
var cubeMaterial = new THREE.MeshFaceMaterial(cubeMaterials);
var cube = new THREE.Mesh(cGeometry, cubeMaterial);
scene.add(cube);
// Create a monolith.
var mGeometry = new THREE.BoxGeometry(1, 2, 1);
var monolithMaterials =
[
new THREE.MeshBasicMaterial({color: 0x000000, wireframe:false}),
new THREE.MeshBasicMaterial({color: 0x000000, wireframe:false}),
new THREE.MeshBasicMaterial({color: 0x000000, wireframe:false}),
new THREE.MeshBasicMaterial({color: 0x000000, wireframe:false}),
new THREE.MeshBasicMaterial({color: 0x000000, wireframe:false}),
new THREE.MeshBasicMaterial({color: 0x000000, wireframe:false})
]
var monolithMaterial = new THREE.MeshFaceMaterial(monolithMaterials);
var monolith = new THREE.Mesh(mGeometry, monolithMaterial);
scene.add(monolith);
// Create the Earth.
var eGeometry = new THREE.SphereGeometry(0.5, 32, 32);
var earthMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/tdJcHkE.jpg'),side: THREE.SphericalRefractionMapping});
var earth = new THREE.Mesh(eGeometry, earthMaterial);
scene.add(earth);
earth.position.set(40, 30, -100);
// Create Mercury.
var mGeometry = new THREE.SphereGeometry(0.2, 32, 32);
var mercuryMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/viNnUiy.jpg'),side: THREE.SphericalRefractionMapping});
var mercury = new THREE.Mesh(mGeometry, mercuryMaterial);
scene.add(mercury);
earth.position.set(40, 30, -100);
// Create Venus.
var vGeometry = new THREE.SphereGeometry(0.4, 32, 32);
var venusMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/Cj3j6jF.jpg'),side: THREE.SphericalRefractionMapping});
var venus = new THREE.Mesh(vGeometry, venusMaterial);
scene.add(venus);
venus.position.set(40, 30, -100);
// Create Mars.
var marsGeometry = new THREE.SphereGeometry(0.35, 32, 32);
var marsMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/NiQgB9a.jpg'),side: THREE.SphericalRefractionMapping});
var mars = new THREE.Mesh(marsGeometry, marsMaterial);
scene.add(mars);
mars.position.set(40, 30, -100);
// Create Jupiter.
var jGeometry = new THREE.SphereGeometry(1, 32, 32);
var jMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/YwDPPhF.jpg'),side: THREE.SphericalRefractionMapping});
var jupiter = new THREE.Mesh(jGeometry, jMaterial);
scene.add(jupiter);
jupiter.position.set(40, 30, -100);
// Create Saturn.
var sGeometry = new THREE.SphereGeometry(0.7, 32, 32);
var sMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/OwB4838.jpg'),side: THREE.SphericalRefractionMapping});
var saturn = new THREE.Mesh(sGeometry, sMaterial);
saturn.position.set(40, 30, -100);
var ringMaterial = new THREE.MeshLambertMaterial({
map: new THREE.TextureLoader().load('https://i.imgur.com/bM77pDK.jpg'),
shading: THREE.SmoothShading,
side: THREE.DoubleSide});
var saturnRing = new THREE.Mesh( new THREE.RingGeometry(0.9, 1.3, 30), ringMaterial);
saturn.add(saturnRing);
saturnRing.rotation.x = 90 * Math.PI / 180;
scene.add(saturn);
// Create Uranus.
var uGeometry = new THREE.SphereGeometry(0.7, 32, 32);
var uMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/a31SOvr.jpg'),side: THREE.SphericalRefractionMapping});
var uranus = new THREE.Mesh(uGeometry, uMaterial);
uranus.position.set(40, 30, -100);
var ringMaterial = new THREE.MeshLambertMaterial({
map: new THREE.TextureLoader().load('https://i.imgur.com/BgstG8f.jpg'),
shading: THREE.SmoothShading,
side: THREE.DoubleSide});
var uranusRing = new THREE.Mesh( new THREE.RingGeometry(1, 1.1, 31), ringMaterial);
uranus.add(uranusRing);
var radians = 0 * Math.PI / 180;
uranus.position.x = Math.cos(radians) * uOrbitRadius;
uranus.position.z = Math.sin(radians) * uOrbitRadius;
uranusRing.rotation.x = 90 * Math.PI / 180;
uranus.rotation.z = 90 * Math.PI / 180;
scene.add(uranus);
// Create Neptune.
var nGeometry = new THREE.SphereGeometry(0.7, 32, 32);
var nMaterial = new THREE.MeshPhongMaterial({ map: new THREE.TextureLoader().load('https://i.imgur.com/C5moeoP.jpg'),side: THREE.SphericalRefractionMapping});
var neptune = new THREE.Mesh(nGeometry, nMaterial);
neptune.position.set(40, 30, -100);
scene.add(neptune);
// Adjust camera.
camera.position.z = 7;
camera.position.y = 1;
// Lighting.
var directionalLight = new THREE.DirectionalLight(0xFFFFFF, 1.5);
directionalLight.position.set(1, 1, 1);
scene.add(directionalLight);
// Game logic.
var update = function() {
earth.rotation.y += 0.01;
mercury.rotation.y += 0.01;
venus.rotation.x += 0.01;
mars.rotation.y += 0.01;
jupiter.rotation.y += 0.01;
saturn.rotation.y += 0.01;
neptune.rotation.y += 0.01;
};
// Draw scene.
var render = function() {
renderer.render(scene, camera);
};
// The orbit.
var eOrbitRadius = 6;
var mOrbitRadius = 2;
var vOrbitRadius = 4;
var marsOrbitRadius = 8;
var jOrbitRadius = 12;
var sOrbitRadius = 16;
var uOrbitRadius = 18;
var nOrbitRadius = 20;
// Orbital speed.
var eDate;
var mDate;
var vDate;
var marsDate;
var jDate;
var sDate;
var uDate;
var nDate;
// Update, render, repeat.
var gameLoop = function() {
eDate = Date.now() * 0.0006;
mDate = Date.now() * 0.0043;
vDate = Date.now() * 0.0008;
marsDate = Date.now() * 0.0003;
jDate = Date.now() * 0.0001;
sDate = Date.now() * 0.00009;
uDate = Date.now() * 0.00007;
nDate = Date.now() * 0.00005;
// Continue orbit.
earth.position.set(Math.cos(eDate) * eOrbitRadius, 0, Math.sin(eDate) * eOrbitRadius);
mercury.position.set(Math.cos(mDate) * mOrbitRadius, 0, Math.sin(mDate) * mOrbitRadius);
venus.position.set(Math.cos(vDate) * vOrbitRadius, 0, Math.sin(vDate) * vOrbitRadius);
mars.position.set(Math.cos(marsDate) * marsOrbitRadius, 0, Math.sin(marsDate) * marsOrbitRadius);
jupiter.position.set(Math.cos(jDate) * jOrbitRadius, 0, Math.sin(jDate) * jOrbitRadius);
saturn.position.set(Math.cos(sDate) * sOrbitRadius, 0, Math.sin(sDate) * sOrbitRadius);
uranus.position.set(Math.cos(uDate) * uOrbitRadius, 0, Math.sin(uDate) * uOrbitRadius);
neptune.position.set(Math.cos(nDate) * nOrbitRadius, 0, Math.sin(nDate) * nOrbitRadius);
requestAnimationFrame(gameLoop);
update();
render();
};
gameLoop();
</script>
</body>
</html>