I am coding a basic program that reads data from a file where each character represents a pixel's color and then displays that info on the screen using pygame.
I've got a block of code that reads the file which works beautifully, but when I try to display the pixels one by one, I get an error that says "descriptor 'set_at' for 'pygame.Surface' objects doesn't apply to 'tuple' object". "Grid" is a 2D array that has the 0 and 1 data from the file.
print("Done processing file, Drawing pixels...")
for i in range(0, height - 2):
for j in range(0, width - 2):
if grid[i][j] == 0:
pygame.Surface.set_at((i, j), "black") #Throws the error
elif grid[i][j] == 1:
pygame.Surface.set_at((i, j), "white")
print("Pixels drawn!")
I'm trying to use the "i" and "j" values to describe the "x" and "y" of the pixel I want to modify, but pygame seems to be reading that as a different data type than I want? I'm not entirely sure why pygame doesn't expect a tuple for coordinates (seems like the most logical data type for cartesian coordinates to me).
I'm very new to pygame, so I'm hoping this is a relatively simple mistake with an easy fix. If you want the docs for this specific function: https://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_at