''' Display the window with BLACK color initally. When KKEYDOWN, change color to RED. When KEYUP, change color to GREEN When MOUSEBOTTONDOWN, change color BLUE by Ching-Shoei Chiang ''' import pygame, sys from pygame.locals import * # (R,G,B) BLACK = (0,0,0) # Three 0 RED = (255,0,0) # Two 0 GREEN = (0,255,0) BLUE = (0,0,255) CYAN = (0,255,255) # One 0 MAGENTA = (255,0,255) YELLOW = (255,255,0) WHITE = (255, 255, 255) # Three 255 pygame.init() wcolor = BLACK screen = pygame.display.set_mode((800, 800)) pygame.display.set_caption("Professor Chiang's Game") r = 0 # Setting the main program loop while True: # Main event loop for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if r == 0: r = 255 else: r = 0 # draw rectangle pygame.draw.rect(screen, (r,0,0), (0,0,400,400)) pygame.draw.rect(screen, (r,255,0), (400,0,400,400)) pygame.draw.rect(screen, (r,0,255), (0,400,400,400)) pygame.draw.rect(screen, (r,255,255), (400,400,400,400)) pygame.display.update()