Making shape change color with keys

I am coding for an assignment and I am having a hard time. I want to make a shape, then particles, change between red. yellow and blue by hitting keys. I can’t tell what I’m doing wrong. Please help!

float offset =180;
boolean isKeyPressedLeft = false;
boolean isKeyPressedDown= false;
boolean isKeyPressedRight= false;

float centerX;
float centerY;

void setup()
{
size(200, 200);
centerX= width / 2.0f;
centerY = height /2.0f;
}

void draw ()
{
background (63);
circle (100, 100, 100);
noStroke();

if (isKeyPressedLeft)
fill ( 228, 46,46);

if (isKeyPressedDown)
fill ( 237, 201,41);

if (isKeyPressedRight)
fill( 56, 76, 228);
}

void keyPressed()
{
updateKeyboard(true);
}

void keyReleased()
{
updateKeyboard(false);
}

void updateKeyboard(boolean state)
{
if (keyCode ==LEFT)
isKeyPressedLeft = state;
if (keyCode ==DOWN)
isKeyPressedLeft = state;
if(keyCode == RIGHT)
isKeyPressedLeft = state;
}

Hi @karbon Welcome to the forum.
In the updateKeyboard() function you are using the same boolean for all keyCodes
Change them like:

if (keyCode == LEFT) isKeyPressedLeft = state;
if (keyCode == DOWN) isKeyPressedDown = state;
if (keyCode == RIGHT) isKeyPressedRight = state;
2 Likes