
# randomRects.py

# draw 100 rectangles at random positions filled with random colors


import pygame, sys, random
from pygame.color import THECOLORS 
from pygame.locals import *


pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill(THECOLORS['white'])
pygame.display.set_caption("Random Rectangles")

for i in range (100):
    # pick random numbers for rectangle size and position
    width = random.randint(0, 250)
    height = random.randint(0, 100)
    top = random.randint(0, 400)
    left = random.randint(0, 500)
    
    # pick a random color by name
    color_name = random.choice( list(THECOLORS.keys()) )
    color = THECOLORS[color_name]
        
    # draw the rectangle
    pygame.draw.rect(screen, color, (left, top, width, height))
    

clock = pygame.time.Clock()

running = True
while running:  # game loop
    clock.tick(30)

    # handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    # update game state  (nothing yet)

    # redraw game
    pygame.display.update()
pygame.quit()
