Why is screen.fill not showing the correct color?

So I have this function

if (colorString[0] == '#') {
                const hex = colorString.replace('#', '');
                let r = parseInt(hex.slice(0, 2), 16);
                let g = parseInt(hex.slice(2, 4), 16);
                let b = parseInt(hex.slice(4, 6), 16);
                return color.rgb(r, g, b);
            };

And I call it here:

screen.fillRect(posX, posY, width + padding * 2, height + padding * 2, Style.color(backgroundColor));

where screen.fillRect is a function that adds a handler to draw that rectangle every frame. But when I use the function the wrong colors appear. This can be minimized by multiplying by four, but it does still leave a lot of error. Is there a solution to this problem?

1 Like

Hello! It looks like you are using PyGame? This forum is for Makecode Arcade. We can’t use more than 16 colors in Arcade, so a lot of people here have no idea what you are trying to do!
The only thing I can see online is that using the .replace method isn’t what people usually do, so maybe it’s doing something weird?
Maybe one of the @moderators can help?

This code is for PXT arcade with typescript.

1 Like

I see. Try making a post in the PXT category. They will know more than us in the Arcade category. Or maybe mods could edit your post to be in that category? Idk. Sometimes if you ask them it magically happens…