Using a nested for loop to create a grid of rectangles in Pygame, why isn’t it drawing correctly?

  pygame, python

I’m trying to create the grid of 5×5 rectangles from part 4 of the Pygame lab here. I’ve created my loop which seems to make logical sense, and the coordinates update correctly while debugging, but when it draws to the screen it comes out in a strange pattern like this:

enter image description here

Here is the loop I’m using:

for x in range(0, 100, 10):
    for y in range(0, 100, 10):
        pygame.draw.rect(screen, GREEN, [(x, y),(x + 5, y + 5)], 1)

I’m obviously doing something stupid here, but can’t figure out what I’m doing wrong. I’ve made the width 1 to help with troubleshooting the issue, that will be removed once it’s fixed to make the rectangles solid.

Source: Python Questions

LEAVE A COMMENT