-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathNASA_Solar_System_Simulator.py
126 lines (104 loc) · 4.64 KB
/
NASA_Solar_System_Simulator.py
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
import math
import pygame
from pygame.locals import *
SCREEN_WIDTH = 1850
SCREEN_HEIGHT = 1850
SUN_RADIUS = 50
# Speed up
# Planet data: name, radius, orbit radius, orbit speed, color
# PLANETS = [
# ("Mercury", 10, 100, 0.02, pygame.Color("#A9A9A9")), # Gray
# ("Venus", 15, 150, 0.015, pygame.Color("#FFA500")), # Orange
# ("Earth", 20, 200, 0.01, pygame.Color("#0000FF")), # Blue
# ("Mars", 17, 250, 0.008, pygame.Color("#FF0000")), # Red
# ("Jupiter", 40, 350, 0.005, pygame.Color("#FFD700")), # Gold
# ("Saturn", 35, 450, 0.004, pygame.Color("#D2B48C")), # Tan
# ("Uranus", 30, 550, 0.003, pygame.Color("#00FFFF")), # Cyan
# ("Neptune", 30, 650, 0.002, pygame.Color("#00008B")), # Dark Blue
# ("Pluto", 8, 750, 0.001, pygame.Color("#A0522D")) # Brown
# ]
# Speed up
# PLANETS = [
# ("Mercury", 10, 100, 0.04, pygame.Color("#A9A9A9")), # Gray
# ("Venus", 15, 150, 0.03, pygame.Color("#FFA500")), # Orange
# ("Earth", 20, 200, 0.02, pygame.Color("#0000FF")), # Blue
# ("Mars", 17, 250, 0.016, pygame.Color("#FF0000")), # Red
# ("Jupiter", 40, 350, 0.01, pygame.Color("#FFD700")), # Gold
# ("Saturn", 35, 450, 0.008, pygame.Color("#D2B48C")), # Tan
# ("Uranus", 30, 550, 0.006, pygame.Color("#00FFFF")), # Cyan
# ("Neptune", 30, 650, 0.004, pygame.Color("#00008B")), # Dark Blue
# ("Pluto", 8, 750, 0.002, pygame.Color("#A0522D")) # Brown
# ]
# Speed up
# PLANETS = [
# ("Mercury", 10, 100, 0.08, pygame.Color("#A9A9A9")), # Gray
# ("Venus", 15, 150, 0.06, pygame.Color("#FFA500")), # Orange
# ("Earth", 20, 200, 0.04, pygame.Color("#0000FF")), # Blue
# ("Mars", 17, 250, 0.032, pygame.Color("#FF0000")), # Red
# ("Jupiter", 40, 350, 0.02, pygame.Color("#FFD700")), # Gold
# ("Saturn", 35, 450, 0.016, pygame.Color("#D2B48C")), # Tan
# ("Uranus", 30, 550, 0.012, pygame.Color("#00FFFF")), # Cyan
# ("Neptune", 30, 650, 0.008, pygame.Color("#00008B")), # Dark Blue
# ("Pluto", 8, 750, 0.004, pygame.Color("#A0522D")) # Brown
# ]
PLANETS = [
("Mercury", 10, 100, 0.2, pygame.Color("#A9A9A9")), # Gray
("Venus", 15, 150, 0.15, pygame.Color("#FFA500")), # Orange
("Earth", 20, 200, 0.1, pygame.Color("#0000FF")), # Blue
("Mars", 17, 250, 0.08, pygame.Color("#FF0000")), # Red
("Jupiter", 40, 350, 0.05, pygame.Color("#FFD700")), # Gold
("Saturn", 35, 450, 0.04, pygame.Color("#D2B48C")), # Tan
("Uranus", 30, 550, 0.03, pygame.Color("#00FFFF")), # Cyan
("Neptune", 30, 650, 0.02, pygame.Color("#00008B")), # Dark Blue
("Pluto", 8, 750, 0.01, pygame.Color("#A0522D")) # Brown
]
class CelestialBody:
def __init__(self, name, radius, orbit_radius, orbit_speed, color):
self.name = name
self.radius = radius
self.orbit_radius = orbit_radius
self.orbit_speed = orbit_speed
self.color = color
self.angle = 0
def update(self, dt):
self.angle += self.orbit_speed * dt
def get_position(self):
x = SCREEN_WIDTH // 2 + math.cos(self.angle) * self.orbit_radius
y = SCREEN_HEIGHT // 2 + math.sin(self.angle) * self.orbit_radius
return x, y
def draw(self, surface):
x, y = self.get_position()
pygame.draw.circle(surface, self.color, (int(x), int(y)), self.radius)
# Draw planet name
font = pygame.font.Font(None, 20)
text = font.render(self.name, True, (255, 255, 255))
text_rect = text.get_rect(center=(int(x), int(y)))
surface.blit(text, text_rect)
# Draw orbit circle
pygame.draw.circle(surface, self.color, (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2), self.orbit_radius, 1)
def main():
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Solar System Simulator")
sun = CelestialBody("Sun", SUN_RADIUS, 0, 0, pygame.Color("yellow"))
planets = []
for planet_data in PLANETS:
name, radius, orbit_radius, orbit_speed, color = planet_data
planet = CelestialBody(name, radius, orbit_radius, orbit_speed, color)
planets.append(planet)
clock = pygame.time.Clock()
is_running = True
while is_running:
dt = clock.tick(60) / 1000.0
for event in pygame.event.get():
if event.type == QUIT:
is_running = False
screen.fill((0, 0, 0)) # Clear the screen
for planet in planets:
planet.update(dt)
planet.draw(screen)
sun.draw(screen)
pygame.display.flip()
pygame.quit()
if __name__ == '__main__':
main()