-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolar.js
More file actions
363 lines (331 loc) · 18 KB
/
solar.js
File metadata and controls
363 lines (331 loc) · 18 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
// This file contains the JavaScript code for the application. It handles the logic for rendering the solar system and any interactive features.
class RealisticMoonsSolarSystem {
constructor() {
this.canvas = document.getElementById('canvas3d');
this.ctx = this.canvas.getContext('2d');
this.centerX = 0;
this.centerY = 0;
this.time = 0;
this.animationSpeed = 0.1; // Much slower for realistic speeds
this.zoom = 1;
this.isPlaying = true;
// Enhanced 3D rotation controls
this.isDragging = false;
this.lastMouseX = 0;
this.lastMouseY = 0;
this.rotationX = 0.2;
this.rotationY = 0.3;
this.rotationZ = 0;
this.mousePos = {x: 0, y: 0};
this.hoveredPlanet = null;
// Camera controls
this.cameraDistance = 1;
this.autoRotate = false;
this.autoRotateSpeed = 0.002;
// Realistic orbital periods (scaled for visualization)
this.planets = [
{
name: 'Sun', emoji: '☀️', color: '#FDB813', size: 35, distance: 0, speed: 0,
type: 'G2V Main-Sequence Star',
moons: 0,
moonDetails: 'The Sun has no moons but gravitationally influences all planetary systems.',
mass: '1.989 × 10³⁰ kg', diameter: '1,392,700 km', temperature: '5,778 K (surface)',
composition: 'Hydrogen (73%), Helium (25%)', age: '4.6 billion years',
description: 'The Sun is a G2V main-sequence star that powers the entire solar system. Its immense gravity holds all planets and their moons in orbit, creating the complex dance of celestial bodies we observe.',
facts: [
'Contains 99.86% of solar system\'s mass',
'Core temperature reaches 15 million°C',
'Solar wind affects all planetary magnetospheres',
'Gravitational influence extends to Oort Cloud',
'Nuclear fusion creates energy for entire system'
],
research: [
'Parker Solar Probe studying solar corona',
'Solar Orbiter mapping solar magnetic field',
'SOHO monitoring solar activity for 25+ years'
]
},
{
name: 'Mercury', emoji: '☿️', color: '#8C7853', size: 6, distance: 100, speed: 0.415, // Realistic: 88 days
type: 'Terrestrial Planet',
moons: 0,
moonDetails: 'Mercury has no moons due to its proximity to the Sun. The Sun\'s powerful gravity prevents any satellites from maintaining stable orbits around Mercury.',
mass: '3.301 × 10²³ kg', diameter: '4,879 km', temperature: '-173°C to 427°C',
composition: 'Iron core (75%), Rocky mantle', age: '4.5 billion years',
description: 'Mercury is the smallest planet and closest to the Sun. Its lack of moons is attributed to the Sun\'s overwhelming gravitational influence, which would destabilize any potential satellites.',
facts: [
'No moons - Sun\'s gravity too strong',
'Extreme temperature variations without atmosphere',
'Heavily cratered surface like the Moon',
'Fastest orbital speed in solar system',
'3:2 spin-orbit resonance'
],
research: [
'MESSENGER mapped entire surface',
'BepiColombo mission currently en route',
'Mariner 10 first to visit Mercury'
]
},
{
name: 'Venus', emoji: '♀️', color: '#FFC649', size: 9, distance: 140, speed: 0.162, // Realistic: 225 days
type: 'Terrestrial Planet',
moons: 0,
moonDetails: 'Venus has no natural satellites. Theories suggest any ancient moons were lost due to tidal forces, impacts, or the planet\'s slow retrograde rotation.',
mass: '4.867 × 10²⁴ kg', diameter: '12,104 km', temperature: '464°C (constant)',
composition: 'CO₂ atmosphere (96%), Sulfuric acid clouds', age: '4.5 billion years',
description: 'Venus rotates backwards and has no moons. The absence of satellites remains a mystery, with theories ranging from ancient collisions to tidal disruption.',
facts: [
'No moons - reasons still debated by scientists',
'Retrograde rotation may have affected moon formation',
'Thick atmosphere creates runaway greenhouse effect',
'Surface pressure 90 times Earth\'s',
'Longest day in solar system (243 Earth days)'
],
research: [
'Soviet Venera missions landed on surface',
'Magellan radar mapped surface features',
'Future VERITAS and DAVINCI+ missions planned'
]
},
{
name: 'Earth', emoji: '🌍', color: '#6B93D6', size: 9, distance: 180, speed: 0.100, // Realistic: 365 days
type: 'Terrestrial Planet',
moons: 1,
moonDetails: 'Earth\'s Moon (Luna) is unusually large relative to its planet. It stabilizes Earth\'s axial tilt, creates tides, and may have been crucial for the development of life.',
mass: '5.972 × 10²⁴ kg', diameter: '12,756 km', temperature: '15°C (average)',
composition: 'Nitrogen (78%), Oxygen (21%) atmosphere', age: '4.54 billion years',
description: 'Earth\'s single large moon is unique in the inner solar system. The Moon stabilizes our planet\'s tilt, creates tides that may have helped early life, and continues to slowly drift away from Earth.',
facts: [
'Moon stabilizes Earth\'s 23.5° axial tilt',
'Tidal forces affect ocean currents and life',
'Moon formed from giant impact 4.5 billion years ago',
'Only planet with confirmed life',
'Moon is slowly moving away (3.8 cm/year)'
],
research: [
'Apollo missions returned 842 pounds of samples',
'Lunar Reconnaissance Orbiter mapping surface',
'Artemis program planning return missions'
]
},
{
name: 'Mars', emoji: '♂️', color: '#CD5C5C', size: 7, distance: 230, speed: 0.053, // Realistic: 687 days
type: 'Terrestrial Planet',
moons: 2,
moonNames: ['Phobos', 'Deimos'],
moonDetails: 'Mars has two small moons: Phobos and Deimos. Both are likely captured asteroids. Phobos orbits so close it will crash into Mars in ~50 million years.',
mass: '6.39 × 10²³ kg', diameter: '6,792 km', temperature: '-65°C (average)',
composition: 'Iron oxide surface, CO₂ atmosphere', age: '4.5 billion years',
description: 'Mars\' two tiny moons are probably captured asteroids. Phobos, the larger moon, orbits closer than any other moon in the solar system and is gradually spiraling inward.',
facts: [
'Phobos: 22 km diameter, orbits in 7.6 hours',
'Deimos: 12 km diameter, orbits in 30.3 hours',
'Both likely captured from asteroid belt',
'Phobos will crash into Mars in 50 million years',
'Deimos may escape Mars\' gravity eventually'
],
research: [
'Soviet Phobos missions attempted moon study',
'Mars Express imaged both moons in detail',
'Future sample return missions planned'
]
},
{
name: 'Jupiter', emoji: '♃', color: '#D8CA9D', size: 25, distance: 340, speed: 0.008, // Realistic: 12 years
type: 'Gas Giant',
moons: 97,
moonDetails: 'Jupiter has 97 known moons, including the four Galilean moons: Io, Europa, Ganymede, and Callisto. Ganymede is the largest moon in the solar system—even bigger than Mercury.',
mass: '1.898 × 10²⁷ kg (318x Earth)', diameter: '143,000 km (11x Earth)', temperature: '-185°C (upper atmosphere)',
composition: 'Hydrogen (89%), Helium (10%), trace methane & ammonia', age: '4.5 billion years',
description: 'Fifth planet from the Sun and the largest in our solar system. Jupiter\'s mass is 318 times that of Earth, and its gravity is so strong it can bend the paths of comets and asteroids. Famous for its colorful cloud bands and the Great Red Spot, a storm larger than Earth that\'s been raging for centuries.',
facts: [
'Fastest spinner: one day lasts just under 10 hours',
'Takes 11.86 Earth years to complete one orbit',
'Great Red Spot storm larger than Earth',
'Strongest magnetic field creating intense radiation belts',
'Has faint rings discovered in 1979 by Voyager 1'
],
research: [
'Studied by Voyager, Galileo, and Juno missions',
'Juno revealed deep insights into structure and weather',
'Europa Clipper launching to study Europa\'s ocean'
]
},
{
name: 'Saturn', emoji: '♄', color: '#FAD5A5', size: 22, distance: 450, speed: 0.003, // Realistic: 29 years
type: 'Gas Giant',
moons: 145,
moonDetails: 'Saturn has over 140 moons, including Titan (larger than Mercury) and Enceladus, which has geysers that shoot water vapor into space.',
mass: '5.683 × 10²⁶ kg', diameter: '120,536 km (9x Earth)', temperature: '-140°C',
composition: 'Hydrogen & Helium, metallic hydrogen core', age: '4.5 billion years',
description: 'Saturn is the sixth planet from the Sun and the second-largest in our solar system—about 9 times wider than Earth. It\'s a gas giant made mostly of hydrogen and helium. Deep within, hydrogen becomes metallic due to immense pressure. Saturn\'s upper layers feature swirling clouds, ammonia ice crystals, and a mysterious hexagonal storm at its north pole.',
facts: [
'Iconic rings made of ice and rock particles spanning 270,000 km',
'Density of 0.687 g/cm³—so light it would float in water',
'Rotates in 10.7 hours making incredibly short days',
'Takes 29.5 Earth years to orbit the Sun',
'Mysterious hexagonal storm at north pole'
],
research: [
'Cassini-Huygens studied system for 13 years',
'Huygens probe landed on Titan surface',
'Dragonfly mission will explore Titan in 2030s'
]
},
{
name: 'Uranus', emoji: '♅', color: '#4FD0E7', size: 14, distance: 550, speed: 0.001, // Realistic: 84 years
type: 'Ice Giant',
moons: 28,
moonDetails: 'Uranus has 28 known moons, all named after Shakespeare characters. The largest are Titania and Oberon. Miranda has a bizarre, fractured surface suggesting past geological activity.',
mass: '8.681 × 10²⁵ kg', diameter: '51,118 km', temperature: '-195°C',
composition: 'Water, methane, ammonia ices', age: '4.5 billion years',
description: 'Uranus\' moons orbit in the planet\'s equatorial plane, which is tilted 98° to its orbit. This creates extreme seasonal variations as the moons experience 42-year-long seasons.',
facts: [
'All moons named after Shakespeare characters',
'Titania and Oberon are largest moons',
'Miranda has bizarre, fractured terrain',
'Moons orbit in planet\'s tilted equatorial plane',
'Experience extreme 42-year seasonal cycles'
],
research: [
'Voyager 2 only spacecraft to visit system',
'Discovered 10 new moons during flyby',
'Future missions proposed but not yet approved'
]
},
{
name: 'Neptune', emoji: '♆', color: '#4B70DD', size: 14, distance: 650, speed: 0.0006, // Realistic: 165 years
type: 'Ice Giant',
moons: 16,
moonDetails: 'Neptune has 16 known moons. Triton is by far the largest and orbits retrograde (backward), suggesting it\'s a captured Kuiper Belt object. It has nitrogen geysers and a thin atmosphere.',
mass: '1.024 × 10²⁶ kg', diameter: '49,528 km', temperature: '-200°C',
composition: 'Water, methane, ammonia ices', age: '4.5 billion years',
description: 'Neptune\'s largest moon Triton is unique - it orbits backward and is likely a captured dwarf planet from the Kuiper Belt. It\'s geologically active with nitrogen geysers.',
facts: [
'Triton orbits retrograde (backward)',
'Triton likely captured Kuiper Belt object',
'Nitrogen geysers on Triton\'s surface',
'Triton is slowly spiraling into Neptune',
'Other moons are small and irregular'
],
research: [
'Voyager 2 discovered 6 new moons',
'Ground-based telescopes found additional moons',
'Triton may be explored by future missions'
]
}
];
this.init();
}
init() {
this.resizeCanvas();
this.setupEventListeners();
this.createStarField();
this.setupUI();
this.animate();
}
resizeCanvas() {
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
this.centerX = this.canvas.width / 2;
this.centerY = this.canvas.height / 2;
}
setupEventListeners() {
window.addEventListener('resize', () => this.resizeCanvas());
// Enhanced mouse controls for 360° rotation
this.canvas.addEventListener('mousedown', (e) => {
this.isDragging = true;
this.lastMouseX = e.clientX;
this.lastMouseY = e.clientY;
this.canvas.style.cursor = 'grabbing';
});
this.canvas.addEventListener('mousemove', (e) => {
this.mousePos.x = e.clientX;
this.mousePos.y = e.clientY;
if (this.isDragging) {
const deltaX = e.clientX - this.lastMouseX;
const deltaY = e.clientY - this.lastMouseY;
// Full 360° rotation
this.rotationY += deltaX * 0.01;
this.rotationX += deltaY * 0.01;
// Allow full rotation without limits
this.rotationY = this.rotationY % (Math.PI * 2);
this.rotationX = this.rotationX % (Math.PI * 2);
this.lastMouseX = e.clientX;
this.lastMouseY = e.clientY;
} else {
this.checkHover(e);
}
});
this.canvas.addEventListener('mouseup', () => {
this.isDragging = false;
this.canvas.style.cursor = 'grab';
});
this.canvas.addEventListener('mouseleave', () => {
this.isDragging = false;
this.canvas.style.cursor = 'grab';
});
this.canvas.addEventListener('wheel', (e) => {
e.preventDefault();
this.zoom += e.deltaY * -0.001;
this.zoom = Math.max(0.1, Math.min(5, this.zoom));
});
this.canvas.addEventListener('click', (e) => {
if (this.hoveredPlanet !== null && !this.isDragging) {
// Handle planet click
}
});
// Enhanced touch controls
let touchStartDistance = 0;
let touchStartZoom = this.zoom;
this.canvas.addEventListener('touchstart', (e) => {
e.preventDefault();
if (e.touches.length === 1) {
this.lastMouseY = e.touches[0].clientY;
} else if (e.touches.length === 2) {
// Handle pinch zoom
}
});
this.canvas.addEventListener('touchmove', (e) => {
e.preventDefault();
if (this.isDragging && e.touches.length === 1) {
this.lastMouseY = e.touches[0].clientY;
} else if (e.touches.length === 2) {
// Handle pinch zoom
}
});
this.canvas.addEventListener('touchend', () => {
this.isDragging = false;
});
}
checkHover(e) {
const rect = this.canvas.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
this.hoveredPlanet = null;
this.planets.forEach((planet, index) => {
// Check if mouse is over planet
});
if (this.hoveredPlanet === null) {
// Hide tooltip
}
}
get3DPosition(planet) {
if (planet.distance === 0) {
// Handle the Sun's position
}
const angle = this.time * planet.speed * this.animationSpeed;
return {
// Calculate 3D position
};
}
projectTo2D(x, y, z) {
// Apply 3D rotations
}
showTooltip(e, planet) {
// Show tooltip with planet information
}
hideTooltip() {
// Hide tooltip
}
}