-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
373 lines (344 loc) · 14.5 KB
/
Copy pathindex.html
File metadata and controls
373 lines (344 loc) · 14.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solar System Calculator</title>
<style>
body {
font-family: 'Fira Mono', 'Consolas', 'Liberation Mono', 'Menlo', 'Monaco', 'Fixedsys', monospace;
background: #f9f9f9;
color: #222;
margin: 0;
padding: 2em;
}
.container {
max-width: 800px;
margin: 2em auto;
background: #fff;
padding: 2em 2.5em;
border-radius: 12px;
box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}
h1, h2 {
text-align: center;
font-weight: 300;
letter-spacing: 1px;
color: #333;
}
h1 {
font-size: 2em;
margin-bottom: 1em;
}
h2 {
margin-top: 2em;
font-size: 1.5em;
}
/* Shared Image Style */
.planet-image {
object-fit: cover;
border-radius: 8px;
}
/* Scaled Planets in Results */
.scaled-planets {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 1em;
margin: 2em 0;
}
.scaled-planet {
display: flex;
align-items: center;
gap: 1em;
text-align: left;
background: #fafafa;
padding: 1em;
border-radius: 8px;
box-shadow: 0 1px 4px rgba(0,0,0,0.05);
transition: transform 0.2s, box-shadow 0.2s;
}
.scaled-planet:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.scaled-planet .planet-image {
height: auto;
flex-shrink: 0;
}
.scaled-planet h3 {
margin-top: 0;
margin-bottom: 0.25em;
font-size: 1.1em;
}
.scaled-planet .planet-info {
margin-top: 0.5em;
font-size: 0.9em;
color: #666;
}
/* Scaled planet sizes */
.scaled-planet[data-planet="sun"] .planet-image { width: 300px; }
.scaled-planet[data-planet="jupiter"] .planet-image { width: 97px; }
.scaled-planet[data-planet="saturn"] .planet-image { width: 133px; }
.scaled-planet[data-planet="uranus"] .planet-image { width: 58px; }
.scaled-planet[data-planet="neptune"] .planet-image { width: 57px; }
.scaled-planet[data-planet="earth"] .planet-image { width: 29px; }
.scaled-planet[data-planet="venus"] .planet-image { width: 28px; }
.scaled-planet[data-planet="mars"] .planet-image { width: 21px; }
.scaled-planet[data-planet="mercury"] .planet-image { width: 18px; }
.scaled-planet[data-planet="pluto"] .planet-image { width: 13px; }
/* Calculators */
.calculator {
margin-top: 3em;
padding: 1.5em;
border: 1px solid #eee;
border-radius: 8px;
}
.input-group {
margin-bottom: 1em;
}
label {
display: block;
margin-bottom: 0.5em;
}
input[type="number"], select {
padding: 0.8em;
border: 1px solid #ddd;
border-radius: 6px;
font-family: inherit;
font-size: 1em;
}
button {
padding: 0.8em 1.5em;
border: none;
background: #333;
color: white;
border-radius: 6px;
cursor: pointer;
font-family: inherit;
font-size: 1em;
transition: background 0.2s;
}
button:hover {
background: #555;
}
/* Results */
.result {
margin-top: 1em;
padding: 1.5em;
background: #f8f9fa;
border: 1px solid #eee;
border-radius: 8px;
}
.planet-results {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1em;
margin-top: 1em;
}
.planet-result {
display: flex;
align-items: center;
gap: 1em;
padding: 1em;
background: #fff;
border-radius: 8px;
}
.planet-result .planet-image {
width: 50px;
height: 50px;
}
.back-link {
display: block;
text-align: center;
margin-top: 2em;
color: #4a90e2;
text-decoration: none;
}
.back-link:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Solar System Calculator</h1>
<div class="calculator">
<h2>Solar System Scale Model Calculator</h2>
<p id="instructionText">Enter the sun's diameter in inches to calculate the scaled planet diameters:</p>
<div class="input-group">
<label for="sunDiameter">Sun's Diameter:</label>
<input type="number" id="sunDiameter" min="0.1" step="0.1" value="36">
<select id="unitSelector" onchange="updateInstructionText()">
<option value="mm">mm</option>
<option value="inches" selected>inches</option>
<option value="feet">feet</option>
</select>
</div>
<button onclick="calculateScale()">Calculate</button>
<div id="scaleResults" class="result"></div>
</div>
<div class="calculator">
<h2>Distance Calculator</h2>
<p>Calculate the distance between any two objects in the solar system.</p>
<div class="input-group">
<label for="object1">First Object:</label>
<select id="object1">
<option value="sun">Sun</option>
<option value="mercury">Mercury</option>
<option value="venus">Venus</option>
<option value="earth" selected>Earth</option>
<option value="mars">Mars</option>
<option value="jupiter">Jupiter</option>
<option value="saturn">Saturn</option>
<option value="uranus">Uranus</option>
<option value="neptune">Neptune</option>
</select>
</div>
<div class="input-group">
<label for="object2">Second Object:</label>
<select id="object2">
<option value="sun">Sun</option>
<option value="mercury">Mercury</option>
<option value="venus">Venus</option>
<option value="earth">Earth</option>
<option value="mars" selected>Mars</option>
<option value="jupiter">Jupiter</option>
<option value="saturn">Saturn</option>
<option value="uranus">Uranus</option>
<option value="neptune">Neptune</option>
</select>
</div>
<button onclick="calculateDistance()">Calculate Distance</button>
<div id="distanceResult" class="result"></div>
</div>
<a href="/" class="back-link">Back to Home</a>
</div>
<script>
const planetData = {
sun: { name: "Sun", diameter: 1392684000000 },
mercury: { name: "Mercury", distance: 57.9, diameter: 4879 },
venus: { name: "Venus", distance: 108.2, diameter: 12104 },
earth: { name: "Earth", distance: 149.6, diameter: 12756 },
mars: { name: "Mars", distance: 227.9, diameter: 6792 },
jupiter: { name: "Jupiter", distance: 778.5, diameter: 142984 },
saturn: { name: "Saturn", distance: 1427, diameter: 120536 },
uranus: { name: "Uranus", distance: 2871, diameter: 51118 },
neptune: { name: "Neptune", distance: 4495, diameter: 49528 }
};
function calculateScale() {
const sunDiameterInput = parseFloat(document.getElementById('sunDiameter').value);
const unit = document.getElementById('unitSelector').value;
let sunDiameterInches;
if (unit === 'mm') {
sunDiameterInches = sunDiameterInput / 25.4;
} else if (unit === 'feet') {
sunDiameterInches = sunDiameterInput * 12;
} else {
sunDiameterInches = sunDiameterInput;
}
if (isNaN(sunDiameterInches) || sunDiameterInches <= 0) {
alert('Please enter a valid diameter for the sun');
return;
}
const scale = sunDiameterInches / 1392700; // Sun's actual diameter in km
const planets = [
{ name: 'Sun', diameter: 1392700, distance: 0, image: 'sun.png' },
{ name: 'Mercury', diameter: 4879, distance: 57900000, image: 'mercury.png' },
{ name: 'Venus', diameter: 12104, distance: 108200000, image: 'venus.png' },
{ name: 'Earth', diameter: 12756, distance: 149600000, image: 'earth.png' },
{ name: 'Mars', diameter: 6792, distance: 227900000, image: 'mars.png' },
{ name: 'Jupiter', diameter: 142984, distance: 778500000, image: 'jupiter.png' },
{ name: 'Saturn', diameter: 120536, distance: 1434000000, image: 'saturn.png' },
{ name: 'Uranus', diameter: 51118, distance: 2871000000, image: 'uranus.png' },
{ name: 'Neptune', diameter: 49528, distance: 4495000000, image: 'neptune.png' },
{ name: 'Pluto', diameter: 2376, distance: 5900000000, image: 'pluto.png' }
];
let resultHTML = '<h2>Scaled Solar System Model</h2>';
resultHTML += '<div class="scaled-planets">';
planets.forEach(planet => {
const scaledDiameter = planet.diameter * scale;
const scaledDistance = planet.distance * scale;
const planetKey = planet.name.toLowerCase();
resultHTML += `
<div class="scaled-planet" data-planet="${planetKey}">
<img src="images/${planet.image}" alt="${planet.name}" class="planet-image">
<div class="planet-details">
<h3>${planet.name}</h3>
<div class="planet-info">
<div>Diameter: ${scaledDiameter.toFixed(2)} inches</div>
<div>Distance from Sun: ${scaledDistance.toFixed(2)} inches</div>
</div>
</div>
</div>
`;
});
resultHTML += '</div>';
document.getElementById('scaleResults').innerHTML = resultHTML;
}
function calculateDistance() {
const planet1 = document.getElementById('object1').value;
const planet2 = document.getElementById('object2').value;
const sunDiameterInput = parseFloat(document.getElementById('sunDiameter').value);
const unit = document.getElementById('unitSelector').value;
let sunDiameterInches;
if (unit === 'mm') {
sunDiameterInches = sunDiameterInput / 25.4;
} else if (unit === 'feet') {
sunDiameterInches = sunDiameterInput * 12;
} else {
sunDiameterInches = sunDiameterInput;
}
if (isNaN(sunDiameterInches) || sunDiameterInches <= 0) {
alert('Please enter a valid diameter for the sun');
return;
}
const realSunDiameterMM = 1392684000000;
const modelSunDiameterMM = sunDiameterInches * 25.4;
const scaleFactor = realSunDiameterMM / modelSunDiameterMM;
const distance1MM = planet1 === 'sun' ? 0 : planetData[planet1].distance * 1e9;
const distance2MM = planet2 === 'sun' ? 0 : planetData[planet2].distance * 1e9;
let scaledDistance;
if (unit === 'mm') {
scaledDistance = Math.abs(distance1MM - distance2MM) / scaleFactor;
} else if (unit === 'feet') {
scaledDistance = Math.abs(distance1MM - distance2MM) / scaleFactor / 304.8;
} else {
scaledDistance = Math.abs(distance1MM - distance2MM) / scaleFactor / 25.4;
}
let resultHTML = '<div class="planet-results">';
if (planet1 !== 'sun') {
resultHTML += `<div class="planet-result">
<img src="images/${planet1}.png" alt="${planetData[planet1].name}" class="planet-image">
<div>${planetData[planet1].name}</div>
</div>`;
} else {
resultHTML += `<div class="planet-result">
<img src="images/sun.png" alt="Sun" class="planet-image">
<div>Sun</div>
</div>`;
}
resultHTML += '<div style="text-align: center; padding: 1em;">↔️</div>';
if (planet2 !== 'sun') {
resultHTML += `<div class="planet-result">
<img src="images/${planet2}.png" alt="${planetData[planet2].name}" class="planet-image">
<div>${planetData[planet2].name}</div>
</div>`;
} else {
resultHTML += `<div class="planet-result">
<img src="images/sun.png" alt="Sun" class="planet-image">
<div>Sun</div>
</div>`;
}
resultHTML += '</div>';
resultHTML += `<p><strong>Distance:</strong> ${scaledDistance.toFixed(2)} ${unit}</p>`;
document.getElementById('distanceResult').innerHTML = resultHTML;
}
function updateInstructionText() {
const unit = document.getElementById('unitSelector').value;
const instructionText = document.getElementById('instructionText');
instructionText.textContent = `Enter the sun's diameter in ${unit} to calculate the scaled planet diameters:`;
}
</script>
</body>
</html>