#imports the pygame library, and sys library.
import pygame, sys
#import all your key names
from pygame.locals import *

def main():
    #initialize the library and start a clock, just in case we want it.
    pygame.init()

    #initialize the clock that will determine how often we render a frame
    clock = pygame.time.Clock()

    #create our canvas that will be draw on.
    resolution = (640, 480)
    canvas = pygame.display.set_mode(resolution)
    pygame.display.set_caption('Rectangle Example')

    #Pick our background and other colors with R,G,B values between 0 and 255
    backgroundColor = pygame.Color(0,0,0)
    greenColor = pygame.Color(100,150,100)
    whiteColor = pygame.Color(255,255,255)


    #for ever and ever, keep rendering a new frame of our game.
    #this is where code that needs to be run every single frame belongs
    while True:
        #get all of our input events that have happened since the last frame
        for event in pygame.event.get():

            #deal with key presses
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    return
        
        #Done dealing with events, lets draw updated things on our canvas
        #fill our canvas with a background color, effectively erasing the last frame
        canvas.fill(backgroundColor)
    
        #Draw a rectangle
        pygame.draw.rect(canvas, greenColor, (70, 30, 40, 100))
        pygame.draw.rect(canvas, whiteColor, (0, 0, 30, 30))

        #done drawing all the stuff on our canvas, now lets show it to the user
        pygame.display.update()

        #wait the amount of time which
        clock.tick(30)
    
main()
