-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
411 lines (358 loc) · 12.4 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html lang="en">
<head>
<title>Merry XMas from Schrödinger Hat</title>
<meta charset="utf-8">
<meta name="theme-color" content="#000">
<meta name="description" content="We wish you a Merry XMas 2020 and a Happy New Year" />
<link rel="stylesheet" href="public/css/photospheres.css">
<link href="https://fonts.googleapis.com/css2?family=Red+Hat+Display" rel=stylesheet />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel=icon type=image/png sizes=32x32 href=/assets/favicon-32x32.png>
<meta prefix="og: http://ogp.me/ns#" name="og:type" content="website">
<meta prefix="og: http://ogp.me/ns#" name="og:image" content="https://xmas2020.schrodinger-hat.it/assets/social.png">
<meta prefix="og: http://ogp.me/ns#" name="og:title" content="Merry XMas from Schrödinger Hat">
<meta prefix="og: http://ogp.me/ns#" name="og:site_name" content="Merry XMas from Schrödinger Hat">
<meta prefix="og: http://ogp.me/ns#" name="og:description" content="We wish you a Merry XMas 2020 and a Happy New Year">
<meta prefix="og: http://ogp.me/ns#" name="twitter:image" content="https://xmas2020.schrodinger-hat.it/assets/social.png">
<meta prefix="og: http://ogp.me/ns#" name="twitter:title" content="Merry XMas from Schrödinger Hat">
<meta prefix="og: http://ogp.me/ns#" name="twitter:description" content="We wish you a Merry XMas 2020 and a Happy New Year">
</head>
<body>
<ul class="lightrope">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<div id="left-text">
<p>Questo è il nostro augurio per un buon Natale 2020</p>
<p>Guardiamo alle stelle, per rilassarci<br/>e scrutrare l'infinito</p>
<p>Speriamo di aver rallegrato le<br/>vostre ore in questi periodi</p>
</div>
<div id="right-text">
<p>Vi auguriamo un 2021 ricco di sfide e cambiamenti</p>
<p>Di ispirazione, di divulgazione e di crescita personale</p>
<p>Ci sentiamo nel 2021 più carichi e spumeggianti che mai!</p>
</div>
<div id="logo"><a href="https://www.schrodinger-hat.it"><img src="assets/favicon-32x32.png" /></a></div>
<script src="public/js/three/three.min.js"></script>
<script src="public/js/three/Projector.js"></script>
<script src="public/js/three/CanvasRenderer.js"></script>
<script>
var cameraController;
var container;
var blogtext;
var isDragging;
var camera, scene, renderer;
var currentSphere;
var previousMousePosition;
var autoRotationQuaternion;
var index;
materials = [];
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var insideSphere = false;
var numSpheres = 0;
var distance;
var textArray;
var info;
function getParameterByName(name) {
url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
let regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return null;
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
index = parseInt(getParameterByName('page'));
if (!index) index = 0;
init();
animate();
function init() {
container = document.createElement('div');
document.body.appendChild(container);
info = document.createElement('div');
info.style.position = 'absolute';
info.style.bottom = '100px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.style.opacity = '0.8';
info.innerHTML = 'Press Enter or Double click';
container.appendChild(info);
blogtext = document.createElement('div');
blogtext.style.position = 'absolute';
blogtext.style.display = 'none';
blogtext.id = 'blogtext';
blogtext.onmouseover = function () { blogtext.style.opacity = '0.8' };
blogtext.onmouseout = function () { blogtext.style.opacity = '0.5' };
container.appendChild(blogtext);
scene = new THREE.Scene();
scene.background = new THREE.Color(0x2e3440);
camera = new THREE.PerspectiveCamera(65, window.innerWidth / window.innerHeight, 1, 4000);
camera.position.x = 300 * index;
camera.position.y = 55;
camera.position.z = 250;
imageArray = ['public/img/photospheres/galaxy.jpg'];
textArray = ['<p>Guardiamo alle stelle per prendere la loro energia, per ispirarci e per rilassarci. Volevamo mettere una immagine di Natale, ma la più appropriata ci è sembrata questa perché libera. Chiunque, quando guarda verso il cielo, rimane affascinato. Così siamo noi. A presto!</p><br/>Image from <a href="https://www.eso.org/public/images/potw2046a/" target="_blank">ESO</a>']
numSpheres = imageArray.length;
sphereArray = [];
meshSphereArray = [];
cameraController = new CameraController(camera);
geometry = new THREE.SphereGeometry(100, 32, 32);
for (i = 0; i < numSpheres; i++) {
materials.push(new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture(imageArray[i]),
}));
materials[i].transparent = true;
sphereArray.push(new THREE.Mesh(geometry, materials[i]));
sphereArray[i].position.set(300 * i, 0, 0);
sphereArray[i].name = "mainsphere";
}
//set the first sphere mesh
currentSphere = sphereArray[index];
scene.add(currentSphere);
//adding my basic wiremesh spheres
for (i = 0; i < numSpheres; i++) {
meshSphereArray.push(new THREE.Mesh(
new THREE.SphereGeometry(105, 128, 64),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.5
})));
meshSphereArray[i].position.set(300 * i, 0, 0);
scene.add(meshSphereArray[i]);
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(60, 64, 64, 6, 6, 1, 0.8),
new THREE.MeshBasicMaterial({
color: 0xCCCCCC,
transparent: true,
opacity: 0.9
})
);
mesh.position.set(300 * i, -80, 25);
scene.add(mesh);
}
//set auto rotation of current sphere
autoRotationQuaternion = new THREE.Quaternion()
.setFromEuler(new THREE.Euler(
0,
0.002,
0,
'XYZ'
));
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xf0f0f0);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
document.addEventListener('touchstart', onDoubleClick, false);
document.addEventListener('mousedown', function (e) { isDragging = true }, false);
document.addEventListener('mouseup', function (e) { isDragging = false }, false);
document.addEventListener('mousemove', onMouseMove, false);
document.addEventListener('dblclick', onDoubleClick, false);
document.addEventListener('keydown', onKeyDown, false);
previousMousePosition = {
x: 0,
y: 0
};
}
function onMouseMove(e) {
var deltaMove = {
x: e.offsetX - previousMousePosition.x,
y: e.offsetY - previousMousePosition.y
};
if (isDragging) {
var deltaRotationQuaternion = new THREE.Quaternion()
.setFromEuler(new THREE.Euler(
toRadians(-deltaMove.y * 0.1),
toRadians(-deltaMove.x * 0.1),
0,
'XYZ'
));
currentSphere.quaternion.multiplyQuaternions(deltaRotationQuaternion, currentSphere.quaternion);
}
previousMousePosition = {
x: e.offsetX,
y: e.offsetY
};
}
function toRadians(angle) {
return angle * (Math.PI / 180);
}
//camera controller class that handles switching between spheres, and zooming in/out of spehres
function CameraController(camera) {
this.camera = camera;
this.destination = 0;
this.state = -1;
this.update = function () {
switch (this.state) {
case 0:
camera.position.x += 5;
currentSphere.material.opacity = Math.max(0, currentSphere.material.opacity - 0.01);
if (camera.position.x > this.destination) {
var selectedObject = scene.getObjectByName("mainsphere");
scene.remove(selectedObject);
currentSphere = sphereArray[index];
currentSphere.material.opacity = 0;
scene.add(currentSphere);
this.state = 1;
}
break;
case 5:
camera.position.x -= 5;
currentSphere.material.opacity = Math.max(0, currentSphere.material.opacity - 0.01);
if (camera.position.x < this.destination) {
var selectedObject = scene.getObjectByName("mainsphere");
scene.remove(selectedObject);
currentSphere = sphereArray[index];
currentSphere.material.opacity = 0;
scene.add(currentSphere);
this.state = 1;
}
break;
case 1:
if (currentSphere.material.opacity < 1) {
currentSphere.material.opacity += 0.01;
} else {
this.state = -1;
}
break;
case 2:
camera.position.x += 5;
if (camera.position.x > numSpheres * 300 + 100) {
camera.position.x = -200;
} else if (camera.position.x == 0) {
reset = false;
var selectedObject = scene.getObjectByName("mainsphere");
scene.remove(selectedObject);
currentSphere = sphereArray[index];
currentSphere.material.opacity = 0;
scene.add(currentSphere);
this.state = 1;
}
break;
case 3:
if (distance < 50) {
this.state = -1;
currentSphere.material.opacity = 1.0;
blogtext.style.display = 'inline';
blogtext.innerHTML = textArray[index];
info.innerHTML = 'Double click to exit or ESC';
} else if (distance < 90) {
camera.position.sub(currentSphere.position).multiplyScalar(0.99).add(currentSphere.position);
currentSphere.scale.x = -1;
currentSphere.material.opacity += 0.05;
} else if (distance > 90) {
camera.position.sub(currentSphere.position).multiplyScalar(0.99).add(currentSphere.position);
currentSphere.material.opacity = Math.max(0, currentSphere.material.opacity - 0.01);
}
break;
case 4:
if (distance > 250) {
this.state = -1;
currentSphere.material.opacity = 1.0;
} else if (distance < 130) {
camera.position.sub(currentSphere.position).multiplyScalar(1.01).add(currentSphere.position);
currentSphere.material.opacity = Math.max(0, currentSphere.material.opacity - 0.01);
} else if (distance > 130) {
camera.position.sub(currentSphere.position).multiplyScalar(1.01).add(currentSphere.position);
currentSphere.scale.x = 1;
currentSphere.material.opacity = Math.min(1, currentSphere.material.opacity + 0.015);
blogtext.style.display = 'none';
info.innerHTML = 'Press Enter or Double click';
}
}
}
}
function onKeyDown (e) {
if (e.keyCode == 27 || e.keyCode == 13) {
onDoubleClick();
}
}
function onDoubleClick() {
if (insideSphere) {
insideSphere = false;
cameraController.state = 4;
document.getElementById('logo').style.opacity = '1';
document.getElementById('left-text').style.opacity = '1';
document.getElementById('right-text').style.opacity = '1';
} else {
insideSphere = true;
cameraController.state = 3;
document.getElementById('logo').style.opacity = '0';
document.getElementById('left-text').style.opacity = '0';
document.getElementById('right-text').style.opacity = '0';
}
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
//stats.begin();
render();
//stats.end();
}
function render() {
let look = new THREE.Vector3(0, -50, -200);
distance = camera.position.distanceTo(currentSphere.position);
cameraController.update();
camera.lookAt(look.add(camera.position));
camera.updateProjectionMatrix();
//rotate all spheres, always
meshSphereArray.forEach(function (entry) {
entry.rotation.y = Date.now() * 0.0001;
});
//currentSphere.rotation.y = Date.now()*0.0001;
currentSphere.quaternion.multiplyQuaternions(autoRotationQuaternion, currentSphere.quaternion);
renderer.render(scene, camera);
}
</script>
</body>
</html>