import pygame, sys, random color = (255,255,255) def bouncing_rect(): global x_speed, y_speed, color move_rect.x += x_speed move_rect.y += y_speed #Collisions if move_rect.right >= screen_w or move_rect.left <= 0: x_speed *= -1 color1 = random.randint(1,255) color2 = random.randint(1,255) color3 = random.randint(1,255) color = (color1,color2,color3) pygame.display.flip() print(color) if move_rect.bottom >= screen_h or move_rect.top <= 0: y_speed *= -1 color1 = random.randint(1,255) color2 = random.randint(1,255) color3 = random.randint(1,255) color = (color1,color2,color3) pygame.display.flip() print(color) pygame.draw.rect(screen, (color), move_rect) pygame.init() clock = pygame.time.Clock() screen_w, screen_h = 1920, 1080 screen = pygame.display.set_mode((screen_w, screen_h)) move_rect = pygame.Rect(350,350,300,160) x_speed, y_speed = 14,10 while True : for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: print("key_board input -> Exit") pygame.quit() sys.exit() screen.fill((30,30,30)) bouncing_rect() pygame.display.flip() clock.tick(60)