File size: 5,380 Bytes
00fe021
 
 
 
 
782cdcc
00fe021
782cdcc
 
 
 
 
 
 
 
 
00fe021
 
 
782cdcc
00fe021
782cdcc
 
 
 
 
 
 
 
 
 
00fe021
 
782cdcc
00fe021
782cdcc
 
 
00fe021
 
 
 
03b058b
1e5f285
00fe021
782cdcc
7d2a0c6
414892d
6f4e78b
00fe021
782cdcc
 
 
 
 
 
 
 
 
 
 
00fe021
782cdcc
 
cae7f30
 
 
 
 
782cdcc
00fe021
782cdcc
 
 
 
 
 
 
157004e
782cdcc
 
 
 
 
157004e
782cdcc
 
 
 
 
157004e
782cdcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c18dbd4
782cdcc
 
 
 
 
 
 
 
 
 
 
 
00fe021
782cdcc
 
 
 
00fe021
782cdcc
 
 
fe8d367
782cdcc
00fe021
 
782cdcc
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
import numpy as np
import math
import plotly.graph_objects as go
import streamlit as st

# THIS FUNCTION CREATES SHPERES
def spheres(size, clr, dist=0): 
    # Set up 100 points. First, do angles
    theta = np.linspace(0,2*np.pi,100)
    phi = np.linspace(0,np.pi,100)
    # Set up coordinates for points on the sphere
    x0 = dist + size * np.outer(np.cos(theta),np.sin(phi))
    y0 = size * np.outer(np.sin(theta),np.sin(phi))
    z0 = size * np.outer(np.ones(100),np.cos(phi))
    # Set up trace
    trace= go.Surface(x=x0, y=y0, z=z0, colorscale=[[0,clr], [1,clr]])
    trace.update(showscale=False)
    return trace

# THIS FUNCTION CREATES ORBITS
def orbits(dist, offset=0, clr='white', wdth=2): 
    # Initialize empty lists for eac set of coordinates
    xcrd=[]
    ycrd=[]
    zcrd=[]
    # Calculate coordinates
    for i in range(0,361):
        xcrd=xcrd+[(round(np.cos(math.radians(i)),5)) * dist + offset]
        ycrd=ycrd+[(round(np.sin(math.radians(i)),5)) * dist]
        zcrd=zcrd+[0]
    trace = go.Scatter3d(x=xcrd, y=ycrd, z=zcrd, marker=dict(size=0.1), line=dict(color=clr,width=wdth))
    return trace

# THIS FUNCTION DEFINES ANNOTATIONS
def annot(xcrd, zcrd, txt, xancr='center'):
    strng=dict(showarrow=False, x=xcrd, 
               y=0, z=zcrd, text=txt, 
               xanchor=xancr, font=dict(color='#BEBEBE',size=12), opacity=0.5)
    return strng

# The Streamlit app
def main():
    st.title('Quite Accurate Solar System Visualization')
    st.write('##### Zoom in to realize how small and insignificant you are! Try to find :ringed_planet: (The planets are 1000x bigger and all orbits are further away from the sun for visual purposes.)')

    # VISUALIZE THE SOLAR SYSTEM
    diameter_km = [1391000, 4900, 12100, 12700, 6800, 143000, 120500, 51100, 49500]
    diameter = [((i / 142984) * 10) for i in diameter_km]  # Scale diameters
    distance_from_sun = [0, 264, 321, 366, 452, 1063, 1784, 3459, 5200]

    # Set up orbit traces
    traces_orbits = [
        orbits(distance_from_sun[1]), # Mercury
        orbits(distance_from_sun[2]), # Venus
        orbits(distance_from_sun[3]), # Earth
        orbits(distance_from_sun[4]), # Mars
        orbits(distance_from_sun[5]), # Jupiter
        orbits(distance_from_sun[6]), # Saturn
        orbits(distance_from_sun[7]), # Uranus
        orbits(distance_from_sun[8])  # Neptune
    ]

    # Use the same to draw a few rings for Saturn
    traces_rings_saturn = [
        orbits(15, distance_from_sun[6], '#827962', 3),
        orbits(16, distance_from_sun[6], '#827962', 3),
        orbits(17, distance_from_sun[6], '#827962', 3),
        orbits(18, distance_from_sun[6], '#827962', 3),
        orbits(19, distance_from_sun[6], '#827962', 3)
    ]

    layout=go.Layout(
        title = 'Solar System',
        showlegend=False,
        margin=dict(l=0, r=0, t=0, b=0),
        scene = dict(
            xaxis=dict(title='Distance from the Sun', 
                       titlefont_color='black', 
                       range=[-6000,6000],
                       backgroundcolor='black',
                       color='black',
                       gridcolor='black'),
            yaxis=dict(title='Distance from the Sun',
                       titlefont_color='black',
                       range=[-6000,6000],
                       backgroundcolor='black',
                       color='black',
                       gridcolor='black'
                      ),
            zaxis=dict(title='', 
                       range=[-6000,6000],
                       backgroundcolor='black',
                       color='white', 
                       gridcolor='black'
                      ),
            annotations=[
                annot(distance_from_sun[0], 200, 'Sun', xancr='left'),
                annot(distance_from_sun[1], 2, 'Mercury'),
                annot(distance_from_sun[2], 6, 'Venus'),
                annot(distance_from_sun[3], 6, 'Earth'),
                annot(distance_from_sun[4], 3, 'Mars'),
                annot(distance_from_sun[5], 70, 'Jupiter'),
                annot(distance_from_sun[6], 60, 'Saturn'),
                annot(distance_from_sun[7], 25, 'Uranus'),
                annot(distance_from_sun[8], 25, 'Neptune'),
            ]
        )
    )

    fig = go.Figure(layout=layout)
    
    # Add spheres for the Sun and planets
    fig.add_trace(spheres(diameter[0], '#ffff00', distance_from_sun[0])) # Sun
    fig.add_trace(spheres(diameter[1], '#87877d', distance_from_sun[1])) # Mercury
    fig.add_trace(spheres(diameter[2], '#d23100', distance_from_sun[2])) # Venus
    fig.add_trace(spheres(diameter[3], '#325bff', distance_from_sun[3])) # Earth
    fig.add_trace(spheres(diameter[4], '#b20000', distance_from_sun[4])) # Mars
    fig.add_trace(spheres(diameter[5], '#ebebd2', distance_from_sun[5])) # Jupiter
    fig.add_trace(spheres(diameter[6], '#ebcd82', distance_from_sun[6])) # Saturn
    fig.add_trace(spheres(diameter[7], '#37ffda', distance_from_sun[7])) # Uranus
    fig.add_trace(spheres(diameter[8], '#2500ab', distance_from_sun[8])) # Neptune

    # Add orbit traces
    for trace in traces_orbits:
        trace.line.color = '#808080'
        fig.add_trace(trace)

    # Add rings for Saturn
    for trace in traces_rings_saturn:
        fig.add_trace(trace)

    st.plotly_chart(fig)

if __name__ == "__main__":
    main()