awacke1 commited on
Commit
6e526ed
·
verified ·
1 Parent(s): 4ba913e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +307 -0
app.py ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import streamlit.components.v1 as components
3
+
4
+ # Configure the page
5
+ st.set_page_config(
6
+ page_title="Solar System Visualization",
7
+ layout="wide",
8
+ initial_sidebar_state="collapsed"
9
+ )
10
+
11
+ # Title
12
+ st.title("Interactive Solar System Visualization 🌌")
13
+
14
+ # HTML/JavaScript content
15
+ SOLAR_SYSTEM_HTML = """
16
+ <!DOCTYPE html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="UTF-8">
20
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
21
+ <title>Our Solar System</title>
22
+ <style>
23
+ body { margin: 0; overflow: hidden; }
24
+ canvas { display: block; width: 100% !important; height: 1024px !important; }
25
+ #crawl-container {
26
+ position: absolute;
27
+ width: 100%;
28
+ height: 1024px;
29
+ overflow: hidden;
30
+ perspective: 400px;
31
+ font-family: Arial, sans-serif;
32
+ }
33
+ #crawl {
34
+ position: absolute;
35
+ top: 100%;
36
+ left: 50%;
37
+ width: 70%;
38
+ transform: translateX(-50%) rotateX(25deg);
39
+ font-size: 24px;
40
+ text-align: justify;
41
+ color: #feda4a;
42
+ }
43
+ .planet-info {
44
+ margin-bottom: 2em;
45
+ }
46
+ </style>
47
+ </head>
48
+ <body>
49
+ <div id="crawl-container">
50
+ <div id="crawl">
51
+ <h1>Our Amazing Solar System 🌌</h1>
52
+
53
+ <div class="planet-info">
54
+ <h2>The Sun ☀️</h2>
55
+ <p>Our star, a G-type main-sequence star (G2V), located at the center of our solar system:
56
+ - Age: 4.6 billion years
57
+ - Surface Temperature: 5,500°C (10,000°F)
58
+ - Diameter: 1.4 million km (865,000 miles)
59
+ - Mass: 333,000x Earth's mass</p>
60
+ </div>
61
+
62
+ <div class="planet-info">
63
+ <h2>Mercury 🪐</h2>
64
+ <p>The smallest and innermost planet:
65
+ - Distance from Sun: 57.9 million km
66
+ - Length of year: 88 Earth days
67
+ - Surface temperature: -180°C to 430°C
68
+ - No moons</p>
69
+ </div>
70
+
71
+ <div class="planet-info">
72
+ <h2>Venus 🌟</h2>
73
+ <p>Earth's "sister planet":
74
+ - Distance from Sun: 108.2 million km
75
+ - Length of year: 225 Earth days
76
+ - Surface temperature: 462°C
77
+ - Rotates backwards compared to most planets</p>
78
+ </div>
79
+
80
+ <div class="planet-info">
81
+ <h2>Earth 🌍</h2>
82
+ <p>Our home planet:
83
+ - Distance from Sun: 149.6 million km
84
+ - Length of year: 365.25 days
85
+ - Only known planet with life
86
+ - One moon: Luna 🌕</p>
87
+ </div>
88
+
89
+ <div class="planet-info">
90
+ <h2>Mars 🔴</h2>
91
+ <p>The Red Planet:
92
+ - Distance from Sun: 227.9 million km
93
+ - Length of year: 687 Earth days
94
+ - Two moons: Phobos and Deimos
95
+ - Home to largest volcano in solar system</p>
96
+ </div>
97
+
98
+ <div class="planet-info">
99
+ <h2>Jupiter ⭐</h2>
100
+ <p>The largest planet:
101
+ - Distance from Sun: 778.5 million km
102
+ - Length of year: 11.9 Earth years
103
+ - 79 known moons
104
+ - Great Red Spot is a giant storm</p>
105
+ </div>
106
+
107
+ <div class="planet-info">
108
+ <h2>Saturn 💫</h2>
109
+ <p>The ringed planet:
110
+ - Distance from Sun: 1.4 billion km
111
+ - Length of year: 29.5 Earth years
112
+ - 82 confirmed moons
113
+ - Spectacular ring system</p>
114
+ </div>
115
+
116
+ <div class="planet-info">
117
+ <h2>Uranus ❄️</h2>
118
+ <p>The tilted planet:
119
+ - Distance from Sun: 2.9 billion km
120
+ - Length of year: 84 Earth years
121
+ - 27 known moons
122
+ - Rotates on its side</p>
123
+ </div>
124
+
125
+ <div class="planet-info">
126
+ <h2>Neptune 💨</h2>
127
+ <p>The windiest planet:
128
+ - Distance from Sun: 4.5 billion km
129
+ - Length of year: 165 Earth years
130
+ - 14 known moons
131
+ - Strongest winds in the solar system</p>
132
+ </div>
133
+ </div>
134
+ </div>
135
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
136
+ <script>
137
+ // Set up the scene, camera, and renderer
138
+ const scene = new THREE.Scene();
139
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
140
+ const renderer = new THREE.WebGLRenderer({ antialias: true });
141
+ renderer.setSize(window.innerWidth, 1024);
142
+ document.body.appendChild(renderer.domElement);
143
+
144
+ // Function to create a celestial body
145
+ function createCelestialBody(radius, color, x, y, z) {
146
+ const geometry = new THREE.SphereGeometry(radius, 32, 32);
147
+ const material = new THREE.MeshPhongMaterial({ color: color });
148
+ const body = new THREE.Mesh(geometry, material);
149
+ body.position.set(x, y, z);
150
+ return body;
151
+ }
152
+
153
+ // Create the Sun and planets (not to scale to fit visualization)
154
+ const sun = createCelestialBody(3, 0xffff00, 0, 0, 0);
155
+ const mercury = createCelestialBody(0.4, 0xa0522d, 4, 0, 0);
156
+ const venus = createCelestialBody(0.6, 0xdeb887, 6, 0, 0);
157
+ const earth = createCelestialBody(0.6, 0x4169e1, 8, 0, 0);
158
+ const moon = createCelestialBody(0.2, 0x808080, 8.8, 0, 0);
159
+ const mars = createCelestialBody(0.5, 0xff4500, 10, 0, 0);
160
+ const jupiter = createCelestialBody(1.2, 0xffa500, 13, 0, 0);
161
+ const saturn = createCelestialBody(1.0, 0xf0e68c, 16, 0, 0);
162
+ const uranus = createCelestialBody(0.8, 0x87ceeb, 19, 0, 0);
163
+ const neptune = createCelestialBody(0.8, 0x4169e1, 22, 0, 0);
164
+
165
+ // Add planets to the scene
166
+ scene.add(sun);
167
+ scene.add(mercury);
168
+ scene.add(venus);
169
+ scene.add(earth);
170
+ scene.add(moon);
171
+ scene.add(mars);
172
+ scene.add(jupiter);
173
+ scene.add(saturn);
174
+ scene.add(uranus);
175
+ scene.add(neptune);
176
+
177
+ // Create starfield
178
+ const starGeometry = new THREE.BufferGeometry();
179
+ const starMaterial = new THREE.PointsMaterial({
180
+ color: 0xFFFFFF,
181
+ size: 0.1,
182
+ transparent: true
183
+ });
184
+
185
+ const starVertices = [];
186
+ for (let i = 0; i < 10000; i++) {
187
+ const x = (Math.random() - 0.5) * 2000;
188
+ const y = (Math.random() - 0.5) * 2000;
189
+ const z = (Math.random() - 0.5) * 2000;
190
+ starVertices.push(x, y, z);
191
+ }
192
+
193
+ starGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starVertices, 3));
194
+ const stars = new THREE.Points(starGeometry, starMaterial);
195
+ scene.add(stars);
196
+
197
+ // Add lighting
198
+ const ambientLight = new THREE.AmbientLight(0x404040);
199
+ scene.add(ambientLight);
200
+
201
+ const sunLight = new THREE.PointLight(0xffffff, 1, 100);
202
+ sunLight.position.set(0, 0, 0);
203
+ scene.add(sunLight);
204
+
205
+ camera.position.z = 30;
206
+
207
+ // Animation function
208
+ function animate() {
209
+ requestAnimationFrame(animate);
210
+
211
+ // Rotate celestial bodies
212
+ sun.rotation.y += 0.001;
213
+ mercury.rotation.y += 0.02;
214
+ venus.rotation.y += 0.015;
215
+ earth.rotation.y += 0.01;
216
+ moon.rotation.y += 0.01;
217
+ mars.rotation.y += 0.008;
218
+ jupiter.rotation.y += 0.004;
219
+ saturn.rotation.y += 0.003;
220
+ uranus.rotation.y += 0.002;
221
+ neptune.rotation.y += 0.001;
222
+
223
+ // Orbit planets
224
+ const time = Date.now() * 0.001;
225
+
226
+ mercury.position.x = Math.cos(time * 0.5) * 4;
227
+ mercury.position.z = Math.sin(time * 0.5) * 4;
228
+
229
+ venus.position.x = Math.cos(time * 0.4) * 6;
230
+ venus.position.z = Math.sin(time * 0.4) * 6;
231
+
232
+ earth.position.x = Math.cos(time * 0.3) * 8;
233
+ earth.position.z = Math.sin(time * 0.3) * 8;
234
+
235
+ // Moon orbits Earth
236
+ moon.position.x = earth.position.x + Math.cos(time * 2) * 0.8;
237
+ moon.position.z = earth.position.z + Math.sin(time * 2) * 0.8;
238
+
239
+ mars.position.x = Math.cos(time * 0.25) * 10;
240
+ mars.position.z = Math.sin(time * 0.25) * 10;
241
+
242
+ jupiter.position.x = Math.cos(time * 0.2) * 13;
243
+ jupiter.position.z = Math.sin(time * 0.2) * 13;
244
+
245
+ saturn.position.x = Math.cos(time * 0.15) * 16;
246
+ saturn.position.z = Math.sin(time * 0.15) * 16;
247
+
248
+ uranus.position.x = Math.cos(time * 0.1) * 19;
249
+ uranus.position.z = Math.sin(time * 0.1) * 19;
250
+
251
+ neptune.position.x = Math.cos(time * 0.08) * 22;
252
+ neptune.position.z = Math.sin(time * 0.08) * 22;
253
+
254
+ // Rotate the starfield
255
+ stars.rotation.y += 0.0002;
256
+
257
+ renderer.render(scene, camera);
258
+ }
259
+
260
+ animate();
261
+
262
+ // Handle window resizing
263
+ window.addEventListener('resize', () => {
264
+ camera.aspect = window.innerWidth / window.innerHeight;
265
+ camera.updateProjectionMatrix();
266
+ renderer.setSize(window.innerWidth, 1024);
267
+ });
268
+
269
+ // Animate the text crawl
270
+ const crawl = document.getElementById('crawl');
271
+ let crawlPosition = 100;
272
+ function animateCrawl() {
273
+ crawlPosition -= 0.02;
274
+ crawl.style.top = crawlPosition + '%';
275
+ if (crawlPosition > -400) {
276
+ requestAnimationFrame(animateCrawl);
277
+ }
278
+ }
279
+ animateCrawl();
280
+ </script>
281
+ </body>
282
+ </html>
283
+ """
284
+
285
+ # Add description
286
+ st.markdown("""
287
+ This visualization shows our solar system with the Sun, all eight planets, and Earth's moon.
288
+ The visualization includes:
289
+ - Rotating planets and moons
290
+ - Orbital movements
291
+ - Detailed information about each celestial body
292
+ - A starfield background
293
+
294
+ Note: The sizes and distances are not to scale to make the visualization more accessible.
295
+ """)
296
+
297
+ # Display the visualization using a custom component
298
+ components.html(SOLAR_SYSTEM_HTML, height=1024, scrolling=False)
299
+
300
+ # Add footer with data sources
301
+ st.markdown("""
302
+ ---
303
+ Data sources:
304
+ - NASA Solar System Exploration
305
+ - European Space Agency (ESA)
306
+ - International Astronomical Union (IAU)
307
+ """)