import pygame import sys # Initialize pygame pygame.init() # Set up the screen WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Simple Animation") # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) # Set up the clock clock = pygame.time.Clock() # Ball properties ball_radius = 30 ball_x = WIDTH // 2 ball_y = HEIGHT // 2 ball_speed_x = 5 ball_speed_y = 5 # Main game loop running = True while running: screen.fill(WHITE) # Event handling for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Update ball position ball_x += ball_speed_x ball_y += ball_speed_y # Bounce off the walls if ball_x + ball_radius > WIDTH or ball_x - ball_radius < 0: ball_speed_x = -ball_speed_x if ball_y + ball_radius > HEIGHT or ball_y - ball_radius < 0: ball_speed_y = -ball_speed_y # Draw ball pygame.draw.circle(screen, RED, (ball_x, ball_y), ball_radius) # Update the display pygame.display.flip() # Cap the frame rate clock.tick(60) # Quit pygame pygame.quit() sys.exit()