broadfield-dev commited on
Commit
824c1ab
·
verified ·
1 Parent(s): b79cc65

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +21 -18
index.html CHANGED
@@ -38,16 +38,16 @@
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 => {
@@ -70,38 +70,42 @@
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,
@@ -113,7 +117,6 @@
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
 
 
38
  const sun = new THREE.Mesh(sunGeometry, sunMaterial);
39
  scene.add(sun);
40
 
41
+ // Planets with more realistic orbital periods
42
  const planets = [
43
+ { name: 'Mercury', distance: 10, scale: 0.2, speed: 0.00582 }, // ~88 Earth days
44
+ { name: 'Venus', distance: 15, scale: 0.4, speed: 0.00224 }, // ~225 Earth days
45
+ { name: 'Earth', distance: 20, scale: 0.5, speed: 0.00199 }, // ~365 Earth days
46
+ { name: 'Mars', distance: 25, scale: 0.3, speed: 0.00106 }, // ~687 Earth days
47
+ { name: 'Jupiter', distance: 35, scale: 2, speed: 0.00028 }, // ~11.86 Earth years
48
+ { name: 'Saturn', distance: 45, scale: 1.5, speed: 0.00013 }, // ~29.46 Earth years
49
+ { name: 'Uranus', distance: 55, scale: 1, speed: 0.00006 }, // ~84 Earth years
50
+ { name: 'Neptune', distance: 65, scale: 1, speed: 0.00004 } // ~164.8 Earth years
51
  ];
52
 
53
  planets.forEach(planet => {
 
70
  }
71
 
72
  // Animation
73
+ let lastTime = 0;
74
+ function animate(time) {
75
  requestAnimationFrame(animate);
76
 
77
+ const deltaTime = time - lastTime;
78
+ lastTime = time;
79
+
80
  planets.forEach((planet, index) => {
81
  const planetMesh = scene.children[3 + index];
82
+ const angle = planet.speed * time * 0.001; // Adjust speed for real-time simulation
83
+ planetMesh.position.x = Math.cos(angle) * planet.distance;
84
+ planetMesh.position.z = Math.sin(angle) * planet.distance;
85
  });
86
 
87
  neos.forEach(neo => {
88
+ neo.position.x += Math.sin(time * 0.001) * 0.1;
89
+ neo.position.z += Math.cos(time * 0.001) * 0.1;
90
  });
91
 
92
  controls.update();
93
  renderer.render(scene, camera);
94
  }
95
 
96
+ animate(0);
97
 
98
  // Fetching NEO data from NASA API
99
  function fetchNEOData() {
100
  fetch('https://api.nasa.gov/neo/rest/v1/feed?start_date=2025-02-18&end_date=2025-02-19&api_key=DEMO_KEY')
101
  .then(response => response.json())
102
  .then(data => {
 
103
  const neoData = data.near_earth_objects['2025-02-18'];
104
  if (neoData) {
105
  neos.forEach((neo, index) => {
106
  if (index < neoData.length) {
107
  const obj = neoData[index];
108
+ // Simplified NEO positioning based on miss distance
109
  neo.position.set(
110
  obj.close_approach_data[0].miss_distance.astronomical * 100 - 50,
111
  obj.close_approach_data[0].miss_distance.astronomical * 50,
 
117
  }).catch(error => console.error('Error fetching NEO data:', error));
118
  }
119
 
 
120
  fetchNEOData(); // Initial fetch
121
  setInterval(fetchNEOData, 3600000); // Update every hour
122