ibrahim yıldız commited on
Commit
fe8d367
·
verified ·
1 Parent(s): c18dbd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -37
app.py CHANGED
@@ -33,49 +33,97 @@ def annot(xcrd, zcrd, txt, xancr='center'):
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
- # Data for the sizes and distances of the planets (in km)
40
- diameter_km = [1392684, 12742, 6780, 142984, 120536, 51118, 49528, 2370]
41
- distance_from_sun_km = [0, 57909175, 108208930, 149597890, 227936640, 778412020, 1433449370, 2870671400]
 
 
42
 
43
- # Scale factors for visualization
44
- scale_factor_diameter = 1e-5
45
- scale_factor_distance = 1e-6
 
 
 
 
 
 
 
 
46
 
47
- layout = go.Layout(
48
- title='Solar System',
49
- showlegend=False,
50
- margin=dict(l=0, r=0, t=0, b=0),
51
- scene=dict(
52
- xaxis=dict(title='Distance from the Sun (million km)', titlefont_color='black', range=[-500, 500]),
53
- yaxis=dict(title='Distance from the Sun (million km)', titlefont_color='black', range=[-500, 500]),
54
- zaxis=dict(title='', range=[-500, 500]),
55
- annotations=[
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
- fig = go.Figure(layout=layout)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
- # Add spheres for the Sun and planets
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
- # Add orbit traces
75
- for i in range(1, len(distance_from_sun_km)):
76
- fig.add_trace(orbits(distance_from_sun_km[i] * scale_factor_distance, clr='#BEBEBE', wdth=1))
 
 
 
 
 
 
 
77
 
78
- st.plotly_chart(fig)
 
 
 
 
 
 
 
 
 
 
79
 
80
  if __name__ == "__main__":
81
- main()
 
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()