Coordinate visualizer

See exactly how Pygame's screen coordinates work. Move the pointer to read positions, place points, draw a Rect and read all of its attributes.

Updated

Pointer

(0, 0)

Points

    Rect

    Drag in “Draw a Rect” mode.

    As Python

    (0, 0) is the top-left corner. x grows to the right, y grows downward.
    On this page

    How to use it#

    1. Set the screen width and height to match your game, and choose the grid spacing.
    2. Move the pointer over the screen: the position appears in the side panel, exactly as pygame.mouse.get_pos() would report it.
    3. In Place points mode, click to add points. In Draw a Rect mode, drag to create a rectangle and read its attributes.
    4. Copy the generated Python to draw your points and rectangle in Pygame.

    With the canvas focused, the arrow keys move a crosshair one pixel at a time (Shift moves one grid cell) and Enter places a point.

    How Pygame coordinates work#

    • The origin (0, 0) is the top-left corner of the window.
    • x increases to the right; y increases downward. Moving "up" means subtracting from y.
    • Positions are measured in pixels. In a 640 × 480 window, the bottom-right pixel is (639, 479).
    • Coordinates outside the window are allowed. Things drawn there are simply not visible, which is handy for objects entering from off-screen.

    Rect attributes#

    A pygame.Rect(x, y, width, height) has many named positions. For Rect(100, 50, 200, 80):

    AttributeValue
    topleft(100, 50)
    topright(300, 50)
    bottomleft(100, 130)
    bottomright(300, 130)
    center(200, 90)
    right, bottom300, 130

    right and bottom are one pixel past the rectangle's last pixel column and row. Assigning any attribute moves the rect, for example rect.center = (320, 240) centres it in a 640 × 480 window. More in the Rect reference.

    Angles and maths#

    Because y points down, angles measured with standard maths functions appear to go clockwise on screen. The pygame.math reference explains how this affects rotations.

    ↑ ↓ to moveEnter to openEsc to close