WorksheetsPygame Shapes
Total questions: 15
Worksheet time: 8mins
How do I import the pygame library?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
How do I initialize the pygame?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
How do I initialize the surface?
import pygame
pygame.init()
DISPLAY = pygame.display.set_mode((400,300))
pygame.display.flip()
How do I update the screen?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
What does display.flip() do?
will update the contents of the entire display
allows to update a portion of the screen, instead of the entire area of the screen
Draw a Rectangle
DISPLAY = pygame.display.set_mode([400,300])
pygame.draw.rect(DISPLAY, color, [30, 30, 60, 60])
pygame.draw.line(DISPLAY, color, [20, 50], [180, 50], 3)
pygame.draw.circle(DISPLAY, color, [300, 300], 200, 3)
Draw a Circle
pygame.draw.arc(DISPLAY, color, [50, 50, 200, 200], 0, pi, 2)
pygame.draw.rect(DISPLAY, color, [30, 30, 60, 60])
pygame.draw.circle(DISPLAY, color, [20, 50], [180, 50], 3)
pygame.draw.circle(DISPLAY, color, (300, 300), 20)
Draw a Polygon
pygame.draw.arc(DISPLAY, color, [50, 50, 200, 200], 0, pi, 2)
pygame.draw.rect(DISPLAY, color, [30, 30, 60, 60])
pygame.draw.polygon(DISPLAY, color, [[300, 100], [100,500], [500,500]])
pygame.draw.polygon(DISPLAY, color, [300, 300], 200, 3)
What is Pygame?
An online store for games
A best-selling online game
A website to create and/or upload game assets for Python
A Python Programming library to create games
How can we create displays/screens with Pygame?
pygame.display.set_mode()
pygame.draw.rect()
pygame.display.set_caption()
pygame.key.get_pressed()
What is the size of the pygame display?
250 x 250
500 x 500
2500 x 2500
5000 x 5000
Which function is used to fill the screen with a color in Pygame?
pygame.display.fill(color)
screen.fill(color)
pygame.fill(color)
surface.fill(DISPLAY)
What function is used to draw a line in Pygame?
pygame.draw.line(DISPLAY, color, [start_coord], [end_coord], width)
pygame.draw.rect(DISPLAY, color, [coordinate, width, height])
pygame.draw.circle(DISPLAY, color, (coordinate), radius)
pygame.draw.polygon(DISPLAY, color, [points])
How do you set the caption of a Pygame window?
pygame.display.set_caption('My Game')
pygame.display.set_mode((width, height))
pygame.display.flip()
pygame.init()
How do you draw an arc in pygame?
Use pygame.draw.circle(DISPLAY, color, (x, y), radius) to draw an arc.
Use pygame.draw.line(DISPLAY, color, [start_pos], [end_pos], thickness) to create an arc.
Use pygame.draw.polygon(DISPLAY, color, [[x1,y1],[x2,y2],[x3,y3]]) to draw an arc.
Use pygame.draw.arc(DISPLAY, color, [x, y, width, height], start_angle, end_angle, thickness) to draw an arc.
