Skip to content
Snippets Groups Projects
Commit 9008dde5 authored by Jacob Slunga's avatar Jacob Slunga
Browse files

done

parent 0350461e
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ background_img = pygame.image.load("galaxy.jpg").convert()
sun_img_original = pygame.image.load("sun.png").convert_alpha()
sun_img_original = pygame.transform.scale(
sun_img_original, (50, 50)
) # Initial sun size
)
earth_img = pygame.image.load("earth.png").convert_alpha()
earth_img = pygame.transform.scale(earth_img, (20, 20))
mars_img = pygame.image.load("mars.jpeg").convert_alpha()
......@@ -25,13 +25,18 @@ font = pygame.font.SysFont(None, 24)
initial_sun_mass = 1.989e30 * mass_scale
sun_mass = initial_sun_mass
scale_factor = 0.05 # Reduced scale factor for more control
max_size = 200 # Limit maximum sun sprite size
scale_factor = 0.3
max_size = 200
def update_sun_sprite():
ratio = sun_mass / initial_sun_mass
sun_size = min(int(50 + scale_factor * ratio * 50), max_size)
sun_size = min(
int(50 + scale_factor * ratio * 50), max_size
)
print(
f"Sun size (pixels): {sun_size}, Ratio: {ratio:.2f}"
)
return pygame.transform.scale(sun_img_original, (sun_size, sun_size)), ratio
......@@ -41,11 +46,18 @@ sun_img, sun_ratio = update_sun_sprite()
class Planet:
def __init__(self, image, pos, mass, velocity=(0, 0)):
self.image = image
self.initial_pos = pygame.Vector2(pos)
self.initial_velocity = pygame.Vector2(velocity)
self.pos = pygame.Vector2(pos)
self.mass = mass
self.velocity = pygame.Vector2(velocity)
self.path = []
def reset(self):
self.pos = self.initial_pos
self.velocity = self.initial_velocity
self.path = []
def gravitational_force(self, sun_pos, sun_mass):
distance = self.pos.distance_to(sun_pos)
direction = (sun_pos - self.pos).normalize()
......@@ -122,9 +134,19 @@ mars = Planet(
increase_sun_mass = Button(10, 730, 150, 30, "Increase Sun Mass")
decrease_sun_mass = Button(10, 770, 150, 30, "Decrease Sun Mass")
reset_button = Button(10, 810, 150, 30, "Reset Simulation")
dt = 3600
def reset_simulation():
global sun_mass, sun_img, sun_ratio
sun_mass = initial_sun_mass
sun_img, sun_ratio = update_sun_sprite()
earth.reset()
mars.reset()
running = True
while running:
for event in pygame.event.get():
......@@ -144,6 +166,8 @@ while running:
elif decrease_sun_mass.is_clicked(event):
sun_mass *= 0.9
sun_img, sun_ratio = update_sun_sprite()
elif reset_button.is_clicked(event):
reset_simulation()
screen.blit(background_img, (0, 0))
scaled_sun_img = pygame.transform.scale(
......@@ -168,8 +192,8 @@ while running:
increase_sun_mass.draw(screen)
decrease_sun_mass.draw(screen)
reset_button.draw(screen)
# Display Sun's mass ratio
ratio_text = font.render(f"Sun Size Ratio: {sun_ratio:.2f}", True, (255, 255, 255))
screen.blit(ratio_text, (10, 10))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment