Drawing Shapes

Goals

  • Learn how to draw various shapes with Pygame’s draw functions.

  • Learn about RGB colors.

  • Learn to use the Pygame Documentation

Starter code

Pygame Template

Video Tutorial

What you need to do

  • Draw a line using pygame.draw.line(). Use the Pygame Docs for details about how to use this function.

  • Draw an arc using pygame.draw.arc()

  • Create a face using the basic shapes

Final Code

import pygame
from pygame.locals import K_ESCAPE, KEYDOWN, QUIT

pygame.init()

WIDTH = 640
HEIGHT = 480
SIZE = (WIDTH, HEIGHT)

screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()

running = True
while running:
    # EVENT HANDLING
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                running = False
        elif event.type == QUIT:
            running = False

    # GAME STATE UPDATES
    # All game math and comparisons happen here

    # DRAWING
    screen.fill((255, 255, 255))  # always the first drawing command

    # rectangle
    pygame.draw.rect(screen, (200, 0, 0), (100, 300, 50, 75))

    # circle
    pygame.draw.circle(screen, (0, 200, 0), (100, 300), 20)

    # ellipse
    pygame.draw.ellipse(screen, (255, 255, 255), (100, 300, 50, 75))

    # line

    # arc


    # Must be the last two lines
    # of the game loop
    pygame.display.flip()
    clock.tick(30)
    #---------------------------


pygame.quit()