# ex09StartingPoint.py A Starting Point for drawing functions # P. Conrad for CS5nm, 10/14/2008 # NOTE: When you run this file, it does NOT draw anything until you type: # draw() # at the Python Shell prompt. # stuff we need to import in order to use PyGame import pygame from pygame.locals import * from sys import exit # A function for running test cases # Note that \ character at the end of a line means that the line continues # on the next line def check_expect(test,check,expect): if (check == expect): print "Test " + test + " passed." else: print "Test " + test + " failed: expected " + str(expect) + \ " but I got " + str(check) # @@@ change the name of makeMyDrawingPoints to have an appropriate name like # makeMySurfboardPoints, or makeMyChristmasTreePoints, etc. # makeMyDrawingPoints make a tuple of points for my drawing # @@@ put an explanation here of what you are trying to draw # # consumes: # x, y (numbers: @@@ describe where this point is--bottom left? bottom right? bottom center? top center? # height, width (@@@ you might need only one of these, or you might need both) # produces # what does it produce? a tuple or a list of points? # a tuple is some values in () separated by commas (see drawSnowManWithTests.py for an example) # a list of points looks like this: [(x,y), (x,y+height), (x+0.5*width, y)] # (see drawHousesWithTests.py for examples) def makeMyDrawingPoints(x,y,width,height): # @@@ Add some assignment statements here that compute the various parts of your drawing return -1 # replace this with the tuple or the list you are returning # @@@ PUT TWO TEST CASES HERE (or at least one... one is better than zero, but won't get full credit) # @@@ rename "drawMyDrawing" to something like "drawSurfboard" or "drawChristmasTree" as needed. # drawMyDrawing -- a function to draw a "@@@ my drawing" with PyGame # consumes: # x, y (numbers: @@@ describe again where this is) # height,width (numbers: width,height @@@ do you need both?) # screen (the screen where we should draw this house) # color (a tuple of (r, g, b) representing a color) # produces # nothing # side effect # draws (@@@ my drawing) on the screen of the size and color given, # at the location given def drawMyDrawing(x,y,width,height,screen,color): lineThickness = 3 # if applicable... # calculate all the points, and unpack them from the tuple into individual variables # e.g. (botX,botY,botR,midX,midY,midR,topX,topY,topR) = makeSnowmanPoints(x,y,height) # Now draw the circles (putting int around the points and radius), or # draw the lines (calling the function that pulls in the list of points) # draw() a function to actually do the drawing # consumes and produces nothing # side effect: we see a window with our drawing # to call this function, type draw() in the Python Shell after you do "Run Module" in IDLE def draw(): # set up a window (a.k.a. a screen) size = width, height = 640,480 pygame.init() screen = pygame.display.set_mode(size) # set up variables for colors (add more colors here if you like) red = (255, 0, 0 ) # an RGB 3-tuple representing red green = (0, 255, 0) white = (255, 255, 255) blue = (0, 0, 255) # main loop while True: # loop forever (or at least until someone generates a QUIT event) for event in pygame.event.get(): if event.type == QUIT: pygame.quit(); exit() screen.fill(white); # Make the whole screen white (you could change this to some other color) # @@@@ Now, draw my Drawing (at least three times in different places) # e.g. three different calls to drawSnowman(100,200,90,screen,red) # or drawHouse(100,200,120,150,screen,red) with different parameters. # But, we don't actually SEE anything until we call "update". pygame.display.update()