Spaces:
Sleeping
Sleeping
ibrahim yıldız commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,49 +33,97 @@ def annot(xcrd, zcrd, txt, xancr='center'):
|
|
| 33 |
|
| 34 |
# The Streamlit app
|
| 35 |
def main():
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
annot(distance_from_sun_km[0] * scale_factor_distance, 40, 'Sun', xancr='left'),
|
| 57 |
-
annot(distance_from_sun_km[1] * scale_factor_distance, 5, 'Mercury'),
|
| 58 |
-
annot(distance_from_sun_km[2] * scale_factor_distance, 9, 'Venus'),
|
| 59 |
-
annot(distance_from_sun_km[3] * scale_factor_distance, 9, 'Earth'),
|
| 60 |
-
annot(distance_from_sun_km[4] * scale_factor_distance, 7, 'Mars'),
|
| 61 |
-
annot(distance_from_sun_km[5] * scale_factor_distance, 30, 'Jupiter'),
|
| 62 |
-
annot(distance_from_sun_km[6] * scale_factor_distance, 28, 'Saturn'),
|
| 63 |
-
annot(distance_from_sun_km[7] * scale_factor_distance, 20, 'Uranus'),
|
| 64 |
-
]
|
| 65 |
-
)
|
| 66 |
-
)
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
| 71 |
-
for i in range(len(diameter_km)):
|
| 72 |
-
fig.add_trace(spheres(diameter_km[i] * scale_factor_diameter, '#ffff00', distance_from_sun_km[i] * scale_factor_distance))
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
-
|
|
|
|
| 33 |
|
| 34 |
# The Streamlit app
|
| 35 |
def main():
|
| 36 |
+
st.title('Solar System Visualization')
|
| 37 |
+
st.write('##### Zoom in to realize how small and insignificant you are!')
|
| 38 |
|
| 39 |
+
# VISUALIZE THE SOLAR SYSTEM
|
| 40 |
+
# Diameters in km
|
| 41 |
+
diameter_km = [1392700, 4879, 12104, 12756, 6792, 142984, 120536, 51118, 49528]
|
| 42 |
+
# Distances from the Sun in millions of km
|
| 43 |
+
distance_from_sun = [0, 57.9, 108.2, 149.6, 227.9, 778.6, 1433.5, 2872.5, 4495.1]
|
| 44 |
|
| 45 |
+
# Set up orbit traces
|
| 46 |
+
traces_orbits = [
|
| 47 |
+
orbits(distance_from_sun[1] * 1000000, eccentricity=0.205, inclination=7.005), # Mercury
|
| 48 |
+
orbits(distance_from_sun[2] * 1000000, eccentricity=0.007, inclination=3.394), # Venus
|
| 49 |
+
orbits(distance_from_sun[3] * 1000000, eccentricity=0.017, inclination=0), # Earth
|
| 50 |
+
orbits(distance_from_sun[4] * 1000000, eccentricity=0.093, inclination=1.850), # Mars
|
| 51 |
+
orbits(distance_from_sun[5] * 1000000, eccentricity=0.048, inclination=1.308), # Jupiter
|
| 52 |
+
orbits(distance_from_sun[6] * 1000000, eccentricity=0.056, inclination=2.488), # Saturn
|
| 53 |
+
orbits(distance_from_sun[7] * 1000000, eccentricity=0.046, inclination=0.773), # Uranus
|
| 54 |
+
orbits(distance_from_sun[8] * 1000000, eccentricity=0.009, inclination=1.774) # Neptune
|
| 55 |
+
]
|
| 56 |
|
| 57 |
+
# Use the same to draw a few rings for Saturn
|
| 58 |
+
traces_rings_saturn = [
|
| 59 |
+
orbits(23 * 120536 / 142984, distance_from_sun[6] * 1000000, inclination=2.488),
|
| 60 |
+
orbits(24 * 120536 / 142984, distance_from_sun[6] * 1000000, inclination=2.488),
|
| 61 |
+
orbits(25 * 120536 / 142984, distance_from_sun[6] * 1000000, inclination=2.488),
|
| 62 |
+
orbits(26 * 120536 / 142984, distance_from_sun[6] * 1000000, inclination=2.488),
|
| 63 |
+
orbits(27 * 120536 / 142984, distance_from_sun[6] * 1000000, inclination=2.488),
|
| 64 |
+
orbits(28 * 120536 / 142984, distance_from_sun[6] * 1000000, inclination=2.488)
|
| 65 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
layout = go.Layout(
|
| 68 |
+
title='Solar System',
|
| 69 |
+
showlegend=False,
|
| 70 |
+
margin=dict(l=0, r=0, t=0, b=0),
|
| 71 |
+
scene=dict(
|
| 72 |
+
xaxis=dict(title='Distance from the Sun (km)',
|
| 73 |
+
titlefont_color='white',
|
| 74 |
+
range=[-7e9, 7e9],
|
| 75 |
+
backgroundcolor='black',
|
| 76 |
+
color='white',
|
| 77 |
+
gridcolor='gray'),
|
| 78 |
+
yaxis=dict(title='Distance from the Sun (km)',
|
| 79 |
+
titlefont_color='white',
|
| 80 |
+
range=[-7e9, 7e9],
|
| 81 |
+
backgroundcolor='black',
|
| 82 |
+
color='white',
|
| 83 |
+
gridcolor='gray'),
|
| 84 |
+
zaxis=dict(title='',
|
| 85 |
+
range=[-7e9, 7e9],
|
| 86 |
+
backgroundcolor='black',
|
| 87 |
+
color='white',
|
| 88 |
+
gridcolor='gray'),
|
| 89 |
+
annotations=[
|
| 90 |
+
annot(0, 40, 'Sun', xancr='left'),
|
| 91 |
+
annot(distance_from_sun[1] * 1000000, 5, 'Mercury'),
|
| 92 |
+
annot(distance_from_sun[2] * 1000000, 9, 'Venus'),
|
| 93 |
+
annot(distance_from_sun[3] * 1000000, 9, 'Earth'),
|
| 94 |
+
annot(distance_from_sun[4] * 1000000, 7, 'Mars'),
|
| 95 |
+
annot(distance_from_sun[5] * 1000000, 30, 'Jupiter'),
|
| 96 |
+
annot(distance_from_sun[6] * 1000000, 28, 'Saturn'),
|
| 97 |
+
annot(distance_from_sun[7] * 1000000, 20, 'Uranus'),
|
| 98 |
+
annot(distance_from_sun[8] * 1000000, 20, 'Neptune'),
|
| 99 |
+
]
|
| 100 |
+
)
|
| 101 |
+
)
|
| 102 |
|
| 103 |
+
fig = go.Figure(layout=layout)
|
|
|
|
|
|
|
| 104 |
|
| 105 |
+
# Add spheres for the Sun and planets
|
| 106 |
+
fig.add_trace(spheres(diameter_km[0] / 2, '#ffff00', 0)) # Sun
|
| 107 |
+
fig.add_trace(spheres(diameter_km[1] / 2, '#87877d', distance_from_sun[1] * 1000000)) # Mercury
|
| 108 |
+
fig.add_trace(spheres(diameter_km[2] / 2, '#d23100', distance_from_sun[2] * 1000000)) # Venus
|
| 109 |
+
fig.add_trace(spheres(diameter_km[3] / 2, '#325bff', distance_from_sun[3] * 1000000)) # Earth
|
| 110 |
+
fig.add_trace(spheres(diameter_km[4] / 2, '#b20000', distance_from_sun[4] * 1000000)) # Mars
|
| 111 |
+
fig.add_trace(spheres(diameter_km[5] / 2, '#ebebd2', distance_from_sun[5] * 1000000)) # Jupiter
|
| 112 |
+
fig.add_trace(spheres(diameter_km[6] / 2, '#ebcd82', distance_from_sun[6] * 1000000)) # Saturn
|
| 113 |
+
fig.add_trace(spheres(diameter_km[7] / 2, '#37ffda', distance_from_sun[7] * 1000000)) # Uranus
|
| 114 |
+
fig.add_trace(spheres(diameter_km[8] / 2, '#2500ab', distance_from_sun[8] * 1000000)) # Neptune
|
| 115 |
|
| 116 |
+
# Add orbit traces
|
| 117 |
+
for trace in traces_orbits:
|
| 118 |
+
trace.line.color = '#808080'
|
| 119 |
+
fig.add_trace(trace)
|
| 120 |
+
|
| 121 |
+
# Add rings for Saturn
|
| 122 |
+
for trace in traces_rings_saturn:
|
| 123 |
+
trace.line.color = '#827962'
|
| 124 |
+
fig.add_trace(trace)
|
| 125 |
+
|
| 126 |
+
st.plotly_chart(fig)
|
| 127 |
|
| 128 |
if __name__ == "__main__":
|
| 129 |
+
main()
|