Pygame Basics
Drawing Shapes
Functions in Pygame
Loops in Pygame
Adding Images
100

In Pygame, the following list represents what color?

[0, 0, 255]

Blue

100

The following function can be used to draw a circle in Pygame:

pygame.draw._______

ellipse

100

What is the advantage of using a function in Pygame?

-Re-using code

-Organizes code into logical "chunks"

100

What is the advantage of using a for loop in Pygame?

Drawing a repeating pattern efficiently

100

Aside from placing text, what else is screen.blit() used for?

Placing an image

200

On a 200x200 px screen in Pygame, where is the coordinate (0, 199) located?

The bottom left corner

200

Observe the code below. How thick is the line drawn?

pygame.draw.line(screen, RED, [4, 7], [8, 10], 2)

2 pixels thick

200

Why is it helpful to draw a drawing in the upper left corner before making it a function?

You ensure that the function draws where it is supposed to without having to do tedious math.

200

Fill in the blank to give the following code a 30px gap between each square drawn.

for x in range(0, 400, __):

    pygame.draw.rect(screen, GREEN, [x, 0, 10, 10])

40

200

What is an example of an acceptable image file type in CodeHS?

.png, .webp, .gif, .jpg (for background)

300

The following line of code displays all drawing to the graphics screen:

pygame.display.____()

flip

300

Fill in the blank to draw an isosceles triangle.

pygame.draw.polygon(screen, BLACK, [[10, 50], [50, 50], [__, 0]])

30

300

To make a function more flexible, you add x and y _________  to specify the a drawing's position.

parameters

300

Fill in the blank to draw exactly 5 squares.

for x in range(0, ___, 20):

    pygame.draw.rect(screen, GREEN, [x, 0, 10, 10])

Any number 81 - 100

300

What is one example of a way you can ensure you have transparent image.

-Use Google Image tools

-White bg in preview --> checkerboard bg in selected photo

-Edit the photo yourself

400

Each iteration of the main while loop in Pygame represents _________.

one frame

400

Write a line of code that draws:

  • A red rectangle with outline width 5

  • Top left corner positioned at (200, 150)

  • With height 100

  • With width 70

pygame.draw.rect(screen, RED, [200, 150, 70, 100], 5)

400

Describe the process of changing code that draws in the upper left corner, to a function that can place the same drawing anywhere.

Place inside a function definition with parameters x and y.

Add x and add y to each x and y coordinate in the drawing.

400

Fill in the blank to give the following code a 10px gap between each CIRCLE drawn.

for x in range(10, 200, 30):

    pygame.draw.ellipse(screen, RED, [x, 10, __,__])

20, 20

400

To resize a picture in Pygame, you should use the function:

pygame.transform.____()

scale

500

What is the line of code that keeps the frame rate at 60 fps?

clock.tick(60)

500

Write a line of code that draws:

  • A blue circle

  • The center of the circle at (200, 150)

  • With radius 50

  • Filled in

pygame.draw.ellipse(screen, BLUE, [150, 100, 100, 100])

500

Write a function that draws an exclamation point at specified coordinates on the screen. The exclamation point should be about 10 pixels wide and 100 px tall.

Answers may vary.

500

Write a for loop that draws 8 red circles in a vertical column that starts at the very top-left corner of the screen.

The circles should be 10px in diameter and 10 pixels apart.

for y in range(0,141, 20):  

    pygame.draw.ellipse(screen, RED, [0, y, 10, 10])

or similar

500

Suppose you had a background image uploaded as "background.png". Write a line of code that loads the image into the program.


bg = pygame.image.load("background.png")