Some Pygame Functions
Draw Circle
- pygame.draw.circle(surface, color, center xy, radius)
- surface is the name of the surface on which you want to draw your figure
- Recall that this was defined by the command: window = pygame.display.set_mode((width,height))
- Where width and height are the user defined dimensions of the window you want to draw in (preferrably these dimensions are
stored as variables)
- color is the color (R,G,B) you want the image to be
- center xy is where you want the center of the circle (as (x,y) coordinates) to be
- Recall that the location (x,y) is x = number of pixels from the left and y = number of pixels from the top
- A couple of examples of locations (x,y) on a screen with dimensions (width,height):
- (0, 0) is the top left corner of the drawing surface
- (width, height) is the bottom right corner of the drawing surface
- (0, height) is the bottom left corner of the drawing surface
- (width, 0) is the top right corner of the drawing surface
- (width/2, height/2) is the center of the drawing surface
- radius is the radius of the circle
Draw Rectangle
- pygame.draw.rect(surface,color,(x,y,w,h))
- surface and color are the same as before!
- (x,y,w,h)
- x is the x coordinate of the top left corner of the rectangle
- y is the y coordinate of the top left corner of the rectangle
- w is the width of the rectangle
- h is the height of the rectangle
Draw Ellipse
- pygame.draw.ellipse(surface,color,(x,y,w,h))
- The arguments are the same as for a rectangle!
- What this function actually does is draw an "invisible" rectangle according to (x,y,w,h) , but what you see is the ellipse that fits inside that rectangle
- (x,y,w,h)
- x is the x coordinate of the top left corner of the rectangle that holds the ellipse
- y is the y coordinate of the top left corner of the rectangle that holds the ellipse
- w is the width of the ellipse
- h is the height of the ellipse
Draw Line
- pygame.draw.line(surface,color,start xy, end xy, thickness)
- surface and color are the same as before!
- start xy are the (x,y) coordinates where you want the line to start
- end xy are the (x,y) coordinates where you want the line to end
- thickness is how thick (measured in number of pixels) you want the line to be