-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
540 lines (456 loc) · 21.1 KB
/
Copy pathindex.html
File metadata and controls
540 lines (456 loc) · 21.1 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
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confronto Ricchezza: Ultra-miliardario vs Tu</title>
<style>
:root {
--primary: #00d2ff;
--secondary: #3a7bd5;
--accent: #ffb142;
--bg-glass: rgba(15, 23, 42, 0.85);
--text: #f8fafc;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: #050505;
color: var(--text);
overflow: hidden;
width: 100vw;
height: 100vh;
}
#canvas-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
/* UI Overlay */
#ui-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
pointer-events: none;
display: flex;
flex-direction: column;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 15px;
pointer-events: auto;
}
h1 {
font-size: 1.6rem;
text-shadow: 0 2px 10px rgba(0, 210, 255, 0.5);
margin-bottom: 5px;
}
.panel {
background: var(--bg-glass);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 12px;
padding: 20px;
pointer-events: auto;
max-width: 400px;
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}
.controls {
margin-bottom: 15px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 6px;
font-size: 0.9rem;
font-weight: 600;
color: #cbd5e1;
}
input[type="number"], select {
width: 100%;
padding: 12px;
background: rgba(0, 0, 0, 0.6);
border: 1px solid #475569;
border-radius: 6px;
color: white;
font-size: 1rem;
outline: none;
transition: border-color 0.3s;
}
input[type="number"]:focus, select:focus {
border-color: var(--primary);
}
.btn-group {
display: flex;
gap: 10px;
margin-top: 15px;
}
button {
flex: 1;
padding: 12px;
border: none;
border-radius: 6px;
font-weight: bold;
font-size: 0.9rem;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
button:active {
transform: scale(0.95);
}
#btn-compare { background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; }
#btn-reset { background: #475569; color: white; }
.camera-btn { background: rgba(255, 255, 255, 0.05); color: #fff; border: 1px solid rgba(255,255,255,0.2); }
.camera-btn:hover { background: rgba(255, 255, 255, 0.1); }
.camera-btn.focus {
color: var(--accent);
border-color: var(--accent);
background: rgba(255, 177, 66, 0.1);
}
.camera-btn.focus:hover { background: rgba(255, 177, 66, 0.2); }
#error-msg { color: #ff4757; font-size: 0.85rem; margin-top: 10px; display: none; }
/* Info Badge */
#info-badge { display: none; }
.stat-row {
display: flex;
justify-content: space-between;
padding: 8px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
font-size: 0.9rem;
}
.stat-row:last-child { border-bottom: none; flex-direction: column; }
.stat-value { font-weight: bold; color: var(--primary); text-align: right; }
.analogy-box {
margin-top: 12px;
padding: 15px;
background: rgba(0, 0, 0, 0.5);
border-left: 4px solid var(--accent);
border-radius: 4px;
font-size: 0.9rem;
color: #e2e8f0;
line-height: 1.5;
}
.analogy-icon {
font-size: 1.5rem;
display: block;
margin-bottom: 5px;
}
@media (max-width: 768px) {
h1 { font-size: 1.4rem; }
.panel { max-width: 100%; }
}
</style>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"
}
}
</script>
</head>
<body>
<div id="canvas-container"></div>
<div id="ui-layer">
<header>
<h1>Confronto Ricchezza 2026</h1>
</header>
<div class="panel controls">
<div class="form-group">
<label for="user-wealth">La tua ricchezza netta (USD):</label>
<input type="number" id="user-wealth" min="0" placeholder="Es. 50000" step="1000">
</div>
<div class="form-group">
<label for="billionaire-select">Seleziona miliardario:</label>
<select id="billionaire-select">
<option value="musk">Elon Musk ($1.1 Trilioni)</option>
<option value="page">Larry Page ($294.1 Miliardi)</option>
<option value="brin">Sergey Brin ($271.3 Miliardi)</option>
<option value="bezos">Jeff Bezos ($248.9 Miliardi)</option>
<option value="ellison">Larry Ellison ($231.5 Miliardi)</option>
</select>
</div>
<div id="error-msg">Inserisci un valore valido.</div>
<div class="btn-group">
<button id="btn-compare">Confronta</button>
<button id="btn-reset">Resetta</button>
</div>
</div>
<div class="panel" id="info-badge">
<div class="stat-row">
<span>Miliardario:</span>
<span class="stat-value" id="stat-bil"></span>
</div>
<div class="stat-row">
<span>Tu:</span>
<span class="stat-value" id="stat-user"></span>
</div>
<div class="stat-row">
<span>Proporzione Volume:</span>
<span class="stat-value" id="stat-ratio-text"></span>
</div>
<div class="stat-row">
<span>Scala nel Mondo Reale:</span>
<div class="analogy-box" id="stat-analogy"></div>
</div>
<div class="btn-group" style="margin-top: 15px;">
<button id="btn-focus-user" class="camera-btn focus">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line><line x1="11" y1="8" x2="11" y2="14"></line><line x1="8" y1="11" x2="14" y2="11"></line></svg>
Focus on Me
</button>
<button id="btn-focus-earth" class="camera-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>
Vista Terra
</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
// 1. Dati
const billionaires = {
musk: { name: "Elon Musk", wealth: 1100000000000 },
page: { name: "Larry Page", wealth: 294100000000 },
brin: { name: "Sergey Brin", wealth: 271300000000 },
bezos: { name: "Jeff Bezos", wealth: 248900000000 },
ellison: { name: "Larry Ellison", wealth: 231500000000 }
};
const formatCurrency = (value) => {
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format(value);
};
// 2. Setup Three.js
const container = document.getElementById('canvas-container');
const scene = new THREE.Scene();
// Plane clipping esageratamente piccolo per non far sparire la tua sfera quando zoomiamo
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.000000001, 10000);
camera.position.set(0, 0, 3.5);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, logarithmicDepthBuffer: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
container.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
// Luci
const ambientLight = new THREE.AmbientLight(0xffffff, 0.2);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff, 2.5, 0, 0);
pointLight.position.set(20, 20, 20);
scene.add(pointLight);
// Luce dedicata a te per illuminare la microsfera
const userLight = new THREE.PointLight(0xffd700, 1.5, 0, 0);
scene.add(userLight);
// 3. Modelli 3D
const starGeometry = new THREE.BufferGeometry();
const starCount = 4000;
const starPositions = new Float32Array(starCount * 3);
for(let i=0; i < starCount * 3; i++) {
starPositions[i] = (Math.random() - 0.5) * 100;
}
starGeometry.setAttribute('position', new THREE.BufferAttribute(starPositions, 3));
const starMaterial = new THREE.PointsMaterial({ color: 0xffffff, size: 0.1, transparent: true, opacity: 0.7 });
const stars = new THREE.Points(starGeometry, starMaterial);
scene.add(stars);
// Terra
const textureLoader = new THREE.TextureLoader();
const earthTextureUrl = 'https://cdn.jsdelivr.net/gh/mrdoob/three.js@master/examples/textures/planets/earth_atmos_2048.jpg';
const earthGeometry = new THREE.SphereGeometry(1, 64, 64);
const earthMaterial = new THREE.MeshStandardMaterial({
map: textureLoader.load(earthTextureUrl),
roughness: 0.8,
metalness: 0.1
});
const earthMesh = new THREE.Mesh(earthGeometry, earthMaterial);
scene.add(earthMesh);
// Sfera Utente
const userGeometry = new THREE.SphereGeometry(1, 32, 32);
const userMaterial = new THREE.MeshStandardMaterial({
color: 0xffd700,
emissive: 0xaa8800,
emissiveIntensity: 0.3,
wireframe: false
});
const userMesh = new THREE.Mesh(userGeometry, userMaterial);
userMesh.visible = false;
scene.add(userMesh);
// Anello indicatore per trovare la microsfera
const markerGeo = new THREE.RingGeometry(0.1, 0.11, 32);
const markerMat = new THREE.MeshBasicMaterial({ color: 0xffb142, side: THREE.DoubleSide, transparent: true, opacity: 0.8 });
const markerMesh = new THREE.Mesh(markerGeo, markerMat);
markerMesh.visible = false;
scene.add(markerMesh);
let visualRatio = 0;
let isTransitioning = false;
let targetCameraPos = new THREE.Vector3();
let targetLookAt = new THREE.Vector3();
// 4. Logica Calcoli
const btnCompare = document.getElementById('btn-compare');
const btnReset = document.getElementById('btn-reset');
const inputWealth = document.getElementById('user-wealth');
const selectBillionaire = document.getElementById('billionaire-select');
const infoBadge = document.getElementById('info-badge');
const errorMsg = document.getElementById('error-msg');
// Funzione granulare per gli oggetti quotidiani e macro-oggetti
function generateAnalogy(ratio) {
const earthRadiusMeters = 6371000;
const r = ratio * earthRadiusMeters;
let icon = '';
let text = '';
// Fasce astronomiche e geografiche (Nuove)
if (r > 1000000) { icon = '🌕'; text = `Grande come la Luna o un intero subcontinente.`; }
else if (r > 500000) { icon = '🗺️'; text = `Grande come una nazione (es. l'Italia o la Francia).`; }
else if (r > 100000) { icon = '🗾'; text = `Grande come una regione intera (es. la Lombardia).`; }
else if (r > 50000) { icon = '🌆'; text = `Grande come un'immensa area metropolitana (es. New York City e dintorni).`; }
else if (r > 10000) { icon = '📍'; text = `Grande come una grande città (es. tutta l'area urbana di Milano o Roma).`; }
// Fasce originali espanse
else if (r > 5000) { icon = '🏔️'; text = `Grande come una montagna enorme (es. Monte Bianco).`; }
else if (r > 2000) { icon = '🌳'; text = `Grande come un parco immenso (es. il Central Park).`; }
else if (r > 1000) { icon = '🏘️'; text = `Grande come un piccolo comune o un intero quartiere.`; }
else if (r > 500) { icon = '🏟️'; text = `Grande come un immenso complesso sportivo o lo Stato del Vaticano.`; }
else if (r > 300) { icon = '🗼'; text = `Grande come un imponente grattacielo (es. Empire State Building).`; }
else if (r > 50) { icon = '🏢'; text = `Grande come un palazzo di molti piani.`; }
else if (r > 10) { icon = '🏠'; text = `Grande come una villa a due piani.`; }
else if (r > 4) { icon = '🚌'; text = `Grande come un autobus o un tir.`; }
else if (r > 1.5) { icon = '🐘'; text = `Grande come un elefante o un furgoncino.`; }
else if (r > 0.8) { icon = '🧍'; text = `Grande come un essere umano adulto.`; }
else if (r > 0.4) { icon = '🐕'; text = `Grande come un cane di grossa taglia.`; }
else if (r > 0.1) { icon = '⚽'; text = `Grande come un pallone da calcio.`; }
else if (r > 0.02) { icon = '🍓'; text = `Grande come una fragola o una noce.`; }
else if (r > 0.005) { icon = '🍚'; text = `Grande come un chicco di riso.`; }
else if (r > 0.001) { icon = '🏖️'; text = `Grande come un granello di sabbia o una capocchia di spillo.`; }
else { icon = '🦠'; text = `Invisibile a occhio nudo (grande come un batterio).`; }
// Formattazione dinamica della dimensione per la UI
let sizeFormatted;
if (r > 1000) {
sizeFormatted = (r / 1000).toFixed(2) + ' km';
} else if (r < 1) {
sizeFormatted = (r * 100).toFixed(2) + ' cm';
} else {
sizeFormatted = r.toFixed(2) + ' metri';
}
return `
<span class="analogy-icon">${icon}</span>
Se la ricchezza del miliardario fosse grande quanto l'intero pianeta Terra, la tua genererebbe una sfera con un raggio di <strong>${sizeFormatted}</strong>.<br><br>
${text}
`;
}
btnCompare.addEventListener('click', () => {
const wealthVal = parseFloat(inputWealth.value);
if (isNaN(wealthVal) || wealthVal <= 0) {
errorMsg.style.display = 'block';
return;
}
errorMsg.style.display = 'none';
const billionaire = billionaires[selectBillionaire.value];
const trueRatio = wealthVal / billionaire.wealth;
visualRatio = Math.sqrt(trueRatio);
userMesh.scale.set(visualRatio, visualRatio, visualRatio);
// Posiziona l'utente a fianco della terra
const distance = 1.3;
userMesh.position.set(distance, 0, 0);
userMesh.visible = true;
// Sposta luci e marker
userLight.position.copy(userMesh.position);
userLight.position.z += visualRatio * 2;
userLight.distance = Math.max(visualRatio * 15, 0.1);
markerMesh.position.copy(userMesh.position);
markerMesh.scale.set(1, 1, 1);
markerMesh.visible = true;
// Aggiorna Interfaccia
document.getElementById('stat-bil').innerText = formatCurrency(billionaire.wealth);
document.getElementById('stat-user').innerText = formatCurrency(wealthVal);
const percent = (trueRatio * 100);
const displayPercent = percent < 0.000001 ? "< 0.000001%" : percent.toFixed(6) + "%";
document.getElementById('stat-ratio-text').innerText = displayPercent;
document.getElementById('stat-analogy').innerHTML = generateAnalogy(visualRatio);
infoBadge.style.display = 'block';
triggerGlobalView();
});
// 5. Controlli Telecamera Avanzati
function triggerGlobalView() {
targetLookAt.set(0, 0, 0);
targetCameraPos.set(0, 0, 3.5);
isTransitioning = true;
}
function triggerUserFocus() {
targetLookAt.copy(userMesh.position);
// Calcola una distanza di zoom dinamica e precisissima per la sfera.
// Seleziona un moltiplicatore di distanza che non compenetri mai l'oggetto.
const zoomDist = Math.max(visualRatio * 4, 0.0000015);
// Posizioniamo la telecamera davanti e leggermente di lato alla sfera
targetCameraPos.set(
userMesh.position.x + (zoomDist * 0.5),
userMesh.position.y + (zoomDist * 0.2),
userMesh.position.z + zoomDist
);
isTransitioning = true;
}
document.getElementById('btn-focus-user').addEventListener('click', triggerUserFocus);
document.getElementById('btn-focus-earth').addEventListener('click', triggerGlobalView);
btnReset.addEventListener('click', () => {
inputWealth.value = '';
userMesh.visible = false;
markerMesh.visible = false;
infoBadge.style.display = 'none';
errorMsg.style.display = 'none';
triggerGlobalView();
});
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// 6. Animazione Fluida
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = clock.getDelta();
earthMesh.rotation.y += 0.05 * delta;
if (userMesh.visible) {
userMesh.rotation.y += 0.8 * delta;
// Il marker guarda sempre in camera e pulsa
markerMesh.lookAt(camera.position);
const scale = 1 + Math.sin(clock.elapsedTime * 4) * 0.15;
// Diminuisci la dimensione dell'anello visivo quando la telecamera fa lo zoom
const distToCam = camera.position.distanceTo(userMesh.position);
// Evita che l'anello diventi gigante quando si zooma
const markerDynamicScale = Math.min(distToCam * 0.3, 1);
markerMesh.scale.set(scale * markerDynamicScale, scale * markerDynamicScale, scale * markerDynamicScale);
}
stars.rotation.y += 0.01 * delta;
// Transizione Telecamera Dinamica
if (isTransitioning) {
// Lerp (Linear Interpolation) per muoversi dolcemente verso il target
camera.position.lerp(targetCameraPos, 0.05);
controls.target.lerp(targetLookAt, 0.05);
// Ferma la transizione quando la telecamera è molto vicina al target previsto
const threshold = Math.max(visualRatio * 0.1, 0.0000001);
if (camera.position.distanceTo(targetCameraPos) < threshold) {
isTransitioning = false;
}
}
controls.update();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>