0 XP
Chapter 7

Drawing Shapes

Draw rectangles, circles, and lines to build game graphics.

Core Concept

pygame.draw has functions for every basic shape — the building blocks of any game.

Theory

Filled rectangle: (surface, color, Rect)pygame.draw.rect(screen, (141, 247, 127), (100, 200, 60, 80)) Circle: (surface, color, center, radius)pygame.draw.circle(screen, (83, 217, 230), (400, 300), 30) Line: (surface, color, start, end, width)pygame.draw.line(screen, (255, 207, 74), (0, 0), (800, 600), 2) Unfilled rect (outline): add border width at endpygame.draw.rect(screen, (242, 109, 91), (50, 50, 100, 100), 3)

Live Demo — Run & Explore

Try it live
Loading...

Output will appear here…

Exercise 1 / 1

📝 Draw a 'night sky' scene: dark background, a yellow circle (moon), and 5 small white circles (stars).

Your solution
Loading...

Output will appear here…

Your First Window
Player Movement