import pygame import sys # Initialize Pygame pygame.init() # Constants WIDTH, HEIGHT = 800, 600 FPS = 60 GRAVITY = 0.5 BOUNCE = -0.7 # Colors WHITE = (255, 255, 255) RED = (255, 0, 0) # Setup display screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Physics Simulation") clock = pygame.time.Clock() # Ball properties ball_radius = 20 ball_x = WIDTH // 2 ball_y = HEIGHT // 2 ball_vel_y = 0 running = True while running: screen.fill(WHITE) # Event loop for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Physics update ball_vel_y += GRAVITY ball_y += ball_vel_y # Bounce on bottom if ball_y + ball_radius > HEIGHT: ball_y = HEIGHT - ball_radius ball_vel_y *= BOUNCE # Draw ball pygame.draw.circle(screen, RED, (int(ball_x), int(ball_y)), ball_radius) pygame.display.flip() clock.tick(FPS) pygame.quit() sys.exit()