Draw the Moon
Part of the Python in a Game Window section of Coddy's Pygame journey. Lesson 4 of 32.
pygame.draw.circle draws a filled circle on the window:
pygame.draw.circle(screen, (240, 230, 160), (320, 240), 30)It takes four things, in this order: the surface to draw on (screen, the window), the colour, the centre as an (x, y) tuple, and the radius in pixels.
x counts pixels from the left edge. y counts pixels from the top edge, going down. (0, 0) is the top left corner and (640, 480) the bottom right, so a bigger y is lower in the window.
Draw after screen.fill(). The fill paints the whole window, so anything drawn before it in the same frame disappears under it.
Challenge
EasyMove the moon to the top right and make it bigger:
- Centre it at
(500, 110). - Give it a radius of
50. - Keep its colour,
(240, 230, 160).
Try it yourself
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Night Sky")
clock = pygame.time.Clock()
# Set things up here, before the game loop.
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Change things here, once a frame.
screen.fill((20, 24, 48))
# Draw here, after the fill.
pygame.draw.circle(screen, (240, 230, 160), (320, 240), 30)
pygame.display.flip()
clock.tick(60)
pygame.quit()
All lessons in Python in a Game Window
Practice on your own: Pygame playground