import pygame

pygame.init()

screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Bouncing Ball")
clock = pygame.time.Clock()

BG     = (15, 15, 30)
YELLOW = (240, 200, 40)

RADIUS = 20
x = 320.0
y = 240.0
speed_x = 3.0
speed_y = 2.0

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    x += speed_x
    y += speed_y

    if x - RADIUS < 0 or x + RADIUS > 640:
        speed_x = -speed_x
        x += speed_x

    if y - RADIUS < 0 or y + RADIUS > 480:
        speed_y = -speed_y
        y += speed_y

    screen.fill(BG)
    pygame.draw.circle(screen, YELLOW, (int(x), int(y)), RADIUS)
    pygame.display.flip()
    clock.tick(60)

pygame.quit()
