Timers and Animation: What Would Disney Do? 179
how much red is in your color, the second number is the amount
of green, and the third is blue. We picked 255 as our value for
green and 0 for red and blue, so our RGB color is all green and no
red or blue.) Our variable GREEN is a constant. We sometimes write
constants—variables we don’t intend to change—in all caps. Since
the color should stay the same throughout our program, we’ve used
all caps for GREEN. We set the radius variable equal to 50 pixels, for a
circle 100 pixels in diameter.
The while loop at y is our game loop, and it will keep running
the Pygame window until the user chooses to exit. The for loop
at z is where we handle all the interactive events that the user
can trigger in our program. In this simple example, the only event
we’re checking for is whether the user clicked the red X to close the
window and exit the program {. If so, keep_going gets set to False
and our game loop ends.
At |, we draw a green circle with a radius of 50 on the screen
window at position (100,100): right 100 and down 100 pixels from
the upper-left corner of the window (see “What’s New in Pygame”
on page 180 for more information on how Pygame’s coordinate
system is different from Turtle’s). We’re using pygame.draw, a
Pygame module for drawing shapes like circles, rectangles, and
line segments. We pass four arguments to the pygame.draw.circle()
function: the surface on which we want to draw the circle (screen),
the color for our circle (GREEN), the coordinates of its center point,
and the radius. The update() function at } tells Pygame to refresh
the screen with the drawing changes.
Finally, when the user exits the game loop, the pygame.quit()
command at ~ clears the pygame module (it undoes all the setup
from u) and closes the screen window so that the program can exit
norma l ly.