├── jupiter.png ├── background.jpg ├── README.md └── main.py /jupiter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techwithtim/Slingshot-Effect-Simulation/HEAD/jupiter.png -------------------------------------------------------------------------------- /background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techwithtim/Slingshot-Effect-Simulation/HEAD/background.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Slingshot-Effect-Simulation 2 | 3 | # 💻 Launch Your Software Development Career Today! 4 | 5 | 🎓 **No degree? No problem!** My program equips you with everything you need to break into tech and land an entry-level software development role. 6 | 7 | 🚀 **Why Join?** 8 | - 💼 **$70k+ starting salary potential** 9 | - 🕐 **Self-paced:** Complete on your own time 10 | - 🤑 **Affordable:** Low risk compared to expensive bootcamps or degrees 11 | - 🎯 **45,000+ job openings** in the market 12 | 13 | 👉 **[Start your journey today!](https://techwithtim.net/dev)** 14 | No experience needed—just your determination. Future-proof your career and unlock six-figure potential like many of our students have! 15 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import math 3 | 4 | pygame.init() 5 | 6 | WIDTH, HEIGHT = 800, 600 7 | win = pygame.display.set_mode((WIDTH, HEIGHT)) 8 | pygame.display.set_caption("Gravitational Slingshot Effect") 9 | 10 | PLANET_MASS = 100 11 | SHIP_MASS = 5 12 | G = 5 13 | FPS = 60 14 | PLANET_SIZE = 50 15 | OBJ_SIZE = 5 16 | VEL_SCALE = 100 17 | 18 | BG = pygame.transform.scale(pygame.image.load("background.jpg"), (WIDTH, HEIGHT)) 19 | PLANET = pygame.transform.scale(pygame.image.load("jupiter.png"), (PLANET_SIZE * 2, PLANET_SIZE * 2)) 20 | 21 | WHITE = (255, 255, 255) 22 | RED = (255, 0, 0) 23 | BLUE = (0, 0, 255) 24 | 25 | class Planet: 26 | def __init__(self, x, y, mass): 27 | self.x = x 28 | self.y = y 29 | self.mass = mass 30 | 31 | def draw(self): 32 | win.blit(PLANET, (self.x - PLANET_SIZE, self.y - PLANET_SIZE)) 33 | 34 | class Spacecraft: 35 | def __init__(self, x, y, vel_x, vel_y, mass): 36 | self.x = x 37 | self.y = y 38 | self.vel_x = vel_x 39 | self.vel_y = vel_y 40 | self.mass = mass 41 | 42 | def move(self, planet=None): 43 | distance = math.sqrt((self.x - planet.x)**2 + (self.y - planet.y)**2) 44 | force = (G * self.mass * planet.mass) / distance ** 2 45 | 46 | acceleration = force / self.mass 47 | angle = math.atan2(planet.y - self.y, planet.x - self.x) 48 | 49 | acceleration_x = acceleration * math.cos(angle) 50 | acceleration_y = acceleration * math.sin(angle) 51 | 52 | self.vel_x += acceleration_x 53 | self.vel_y += acceleration_y 54 | 55 | self.x += self.vel_x 56 | self.y += self.vel_y 57 | 58 | def draw(self): 59 | pygame.draw.circle(win, RED, (int(self.x), int(self.y)), OBJ_SIZE) 60 | 61 | def create_ship(location, mouse): 62 | t_x, t_y = location 63 | m_x, m_y = mouse 64 | vel_x = (m_x - t_x) / VEL_SCALE 65 | vel_y = (m_y - t_y) / VEL_SCALE 66 | obj = Spacecraft(t_x, t_y, vel_x, vel_y, SHIP_MASS) 67 | return obj 68 | 69 | def main(): 70 | running = True 71 | clock = pygame.time.Clock() 72 | 73 | planet = Planet(WIDTH // 2, HEIGHT // 2, PLANET_MASS) 74 | objects = [] 75 | temp_obj_pos = None 76 | 77 | while running: 78 | clock.tick(FPS) 79 | 80 | mouse_pos = pygame.mouse.get_pos() 81 | for event in pygame.event.get(): 82 | if event.type == pygame.QUIT: 83 | running = False 84 | 85 | if event.type == pygame.MOUSEBUTTONDOWN: 86 | if temp_obj_pos: 87 | obj = create_ship(temp_obj_pos, mouse_pos) 88 | objects.append(obj) 89 | temp_obj_pos = None 90 | else: 91 | temp_obj_pos = mouse_pos 92 | 93 | win.blit(BG, (0, 0)) 94 | 95 | if temp_obj_pos: 96 | pygame.draw.line(win, WHITE, temp_obj_pos, mouse_pos, 2) 97 | pygame.draw.circle(win, RED, temp_obj_pos, OBJ_SIZE) 98 | 99 | for obj in objects[:]: 100 | obj.draw() 101 | obj.move(planet) 102 | off_screen = obj.x < 0 or obj.x > WIDTH or obj.y < 0 or obj.y > HEIGHT 103 | collided = math.sqrt((obj.x - planet.x)**2 + (obj.y - planet.y)**2) <= PLANET_SIZE 104 | if off_screen or collided: 105 | objects.remove(obj) 106 | 107 | planet.draw() 108 | 109 | pygame.display.update() 110 | 111 | pygame.quit() 112 | 113 | if __name__ == "__main__": 114 | main() --------------------------------------------------------------------------------