How to color a single pixel in pygame zero

61 Views Asked by At

I can't and don't want to know how to use images in pygame zero. I thought of an alternative by making a spritesheet with the def function. I can't figure out how to color a pixel in a specific position though :/

I don't really know how to do it, but this would be my best guess

import pgzrun
HEIGHT = 100
WIDTH = 100
red = (255, 0, 0)
yellow = (255, 255, 0)
white = (255, 255, 255)
teal = (0, 255, 255)
blue = (0, 0, 255)
green = (0, 255, 0)
magenta = (255, 0, 255)
black = (0, 0, 0)

def draw():
    screen.clear()
    screen.fill(white)
    screen.fill((50,50)color = green)
pgzrun.go()

this program is supposed to make the center of the screen green this program doesn't work

2

There are 2 best solutions below

1
Leafy On

The problem is that screen.fill fills the entire screen and you can't give a specific position to the place where it fills. Another thing that's wrong is you make a function called draw and then put in screen.fill. I personally don't recommend pg zero to do these types of things because it's really simple. Instead, try using Pygame. I hope this helped!

0
Bee_Baguette On

You could try using either draw.filled_circle or draw.filled_rect depending on the shape you need.

For draw.filled_circle you give the position as an argument directly, so that might be easier. But if you want to use draw.filled_rect you'll need to set things up like this:

green = (0,255,0)
box = Rect((20, 20), (100, 100)) # or wherever you need to put it

def draw():
    draw.filled_rect(box, green)

Here's the documentation as well, for extra guidance.