Spaces:
Running
Running
Update index.html
Browse files- index.html +94 -72
index.html
CHANGED
@@ -3,98 +3,120 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Solar System with NEOs</title>
|
7 |
<style>
|
8 |
-
body { margin: 0;
|
9 |
-
canvas {
|
10 |
</style>
|
11 |
</head>
|
12 |
<body>
|
13 |
-
<
|
14 |
-
|
15 |
<script>
|
16 |
-
//
|
17 |
-
const
|
18 |
-
const
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
-
//
|
23 |
-
const
|
24 |
-
|
25 |
-
|
26 |
-
radius: 20,
|
27 |
-
color: '#ffcc00'
|
28 |
-
};
|
29 |
|
30 |
-
//
|
31 |
-
const
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
{ name: 'Jupiter', distance: 220, radius: 12, color: '#ff9933', speed: 0.002 },
|
37 |
-
{ name: 'Saturn', distance: 280, radius: 10, color: '#ffcc66', speed: 0.0015 },
|
38 |
-
{ name: 'Uranus', distance: 320, radius: 8, color: '#00ccff', speed: 0.001 },
|
39 |
-
{ name: 'Neptune', distance: 360, radius: 8, color: '#0066ff', speed: 0.0008 }
|
40 |
-
];
|
41 |
|
42 |
-
//
|
43 |
-
const
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
{ name: '
|
51 |
-
{ name: '
|
52 |
-
{ name: '
|
53 |
-
{ name: '
|
|
|
|
|
|
|
|
|
54 |
];
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
ctx.fillStyle = sun.color;
|
67 |
-
ctx.fill();
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
const y = sun.y + Math.sin(angle) * planet.distance;
|
74 |
-
|
75 |
-
ctx.beginPath();
|
76 |
-
ctx.arc(x, y, planet.radius, 0, Math.PI * 2);
|
77 |
-
ctx.fillStyle = planet.color;
|
78 |
-
ctx.fill();
|
79 |
});
|
80 |
|
81 |
-
// Draw NEOs
|
82 |
neos.forEach(neo => {
|
83 |
-
|
84 |
-
|
85 |
-
const y = sun.y + Math.sin(angle) * neo.distance;
|
86 |
-
|
87 |
-
ctx.beginPath();
|
88 |
-
ctx.arc(x, y, neo.radius, 0, Math.PI * 2);
|
89 |
-
ctx.fillStyle = neo.color;
|
90 |
-
ctx.fill();
|
91 |
});
|
92 |
|
93 |
-
|
94 |
-
|
95 |
}
|
96 |
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
</script>
|
99 |
</body>
|
100 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>3D Solar System with NEOs</title>
|
7 |
<style>
|
8 |
+
body { margin: 0; overflow: hidden; }
|
9 |
+
canvas { width: 100%; height: 100%; }
|
10 |
</style>
|
11 |
</head>
|
12 |
<body>
|
13 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
14 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
|
15 |
<script>
|
16 |
+
// Scene setup
|
17 |
+
const scene = new THREE.Scene();
|
18 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
19 |
+
const renderer = new THREE.WebGLRenderer();
|
20 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
21 |
+
document.body.appendChild(renderer.domElement);
|
22 |
|
23 |
+
// Orbit controls for camera movement
|
24 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
25 |
+
camera.position.set(0, 20, 100);
|
26 |
+
controls.update();
|
|
|
|
|
|
|
27 |
|
28 |
+
// Lights
|
29 |
+
const ambientLight = new THREE.AmbientLight(0x404040);
|
30 |
+
scene.add(ambientLight);
|
31 |
+
const pointLight = new THREE.PointLight(0xffffff);
|
32 |
+
pointLight.position.set(0, 100, 100);
|
33 |
+
scene.add(pointLight);
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
// Sun
|
36 |
+
const sunGeometry = new THREE.SphereGeometry(5, 32, 32);
|
37 |
+
const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffcc00 });
|
38 |
+
const sun = new THREE.Mesh(sunGeometry, sunMaterial);
|
39 |
+
scene.add(sun);
|
40 |
+
|
41 |
+
// Planets
|
42 |
+
const planets = [
|
43 |
+
{ name: 'Mercury', distance: 10, scale: 0.2 },
|
44 |
+
{ name: 'Venus', distance: 15, scale: 0.4 },
|
45 |
+
{ name: 'Earth', distance: 20, scale: 0.5 },
|
46 |
+
{ name: 'Mars', distance: 25, scale: 0.3 },
|
47 |
+
{ name: 'Jupiter', distance: 35, scale: 2 },
|
48 |
+
{ name: 'Saturn', distance: 45, scale: 1.5 },
|
49 |
+
{ name: 'Uranus', distance: 55, scale: 1 },
|
50 |
+
{ name: 'Neptune', distance: 65, scale: 1 }
|
51 |
];
|
52 |
|
53 |
+
planets.forEach(planet => {
|
54 |
+
const geometry = new THREE.SphereGeometry(planet.scale, 32, 32);
|
55 |
+
const material = new THREE.MeshPhongMaterial({ color: Math.random() * 0xffffff });
|
56 |
+
const mesh = new THREE.Mesh(geometry, material);
|
57 |
+
mesh.position.x = planet.distance;
|
58 |
+
scene.add(mesh);
|
59 |
+
});
|
60 |
|
61 |
+
// NEOs (fictional for now, will update with real data)
|
62 |
+
let neos = [];
|
63 |
+
for (let i = 0; i < 10; i++) {
|
64 |
+
const geometry = new THREE.SphereGeometry(0.1, 32, 32);
|
65 |
+
const material = new THREE.MeshBasicMaterial({ color: 0xcccccc });
|
66 |
+
const neo = new THREE.Mesh(geometry, material);
|
67 |
+
neo.position.set(Math.random() * 30 - 15, Math.random() * 10 - 5, Math.random() * 30 - 15);
|
68 |
+
scene.add(neo);
|
69 |
+
neos.push(neo);
|
70 |
+
}
|
71 |
|
72 |
+
// Animation
|
73 |
+
function animate() {
|
74 |
+
requestAnimationFrame(animate);
|
|
|
|
|
75 |
|
76 |
+
planets.forEach((planet, index) => {
|
77 |
+
const planetMesh = scene.children[3 + index];
|
78 |
+
planetMesh.position.x = Math.cos(Date.now() * 0.001 * (index + 1)) * planet.distance;
|
79 |
+
planetMesh.position.z = Math.sin(Date.now() * 0.001 * (index + 1)) * planet.distance;
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
});
|
81 |
|
|
|
82 |
neos.forEach(neo => {
|
83 |
+
neo.position.x += Math.sin(Date.now() * 0.001) * 0.1;
|
84 |
+
neo.position.z += Math.cos(Date.now() * 0.001) * 0.1;
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
});
|
86 |
|
87 |
+
controls.update();
|
88 |
+
renderer.render(scene, camera);
|
89 |
}
|
90 |
|
91 |
+
animate();
|
92 |
+
|
93 |
+
// Fetching NEO data from NASA API
|
94 |
+
function fetchNEOData() {
|
95 |
+
fetch('https://api.nasa.gov/neo/rest/v1/feed?start_date=2025-02-18&end_date=2025-02-19&api_key=DEMO_KEY')
|
96 |
+
.then(response => response.json())
|
97 |
+
.then(data => {
|
98 |
+
// Update NEOs with real data
|
99 |
+
const neoData = data.near_earth_objects['2025-02-18'];
|
100 |
+
if (neoData) {
|
101 |
+
neos.forEach((neo, index) => {
|
102 |
+
if (index < neoData.length) {
|
103 |
+
const obj = neoData[index];
|
104 |
+
// Note: This is a very simplistic representation. Real trajectory calculation would require more complex physics.
|
105 |
+
neo.position.set(
|
106 |
+
obj.close_approach_data[0].miss_distance.astronomical * 100 - 50,
|
107 |
+
obj.close_approach_data[0].miss_distance.astronomical * 50,
|
108 |
+
obj.close_approach_data[0].miss_distance.astronomical * 100 - 50
|
109 |
+
);
|
110 |
+
}
|
111 |
+
});
|
112 |
+
}
|
113 |
+
}).catch(error => console.error('Error fetching NEO data:', error));
|
114 |
+
}
|
115 |
+
|
116 |
+
// Update NEO data periodically
|
117 |
+
fetchNEOData(); // Initial fetch
|
118 |
+
setInterval(fetchNEOData, 3600000); // Update every hour
|
119 |
+
|
120 |
</script>
|
121 |
</body>
|
122 |
</html>
|