Is there a way to change color of an already made object?

farbrorbarbro :

I'm making a program in processing, and want to change the color (fill) of an object I've already made. I used the fill(0,0,0) command to change the color to black, but I want a way to change the color of it to 255,0,0 (red). Is there a way to change it, or do I just have to make a new ellipse above it?

I've tried making a variable inside the first fill "fill(test,0,0) where I changed the value of "test" from 0 to 255, didn't work

void draw() {
  fill(0,0,0);
  ellipse(490, 140, 100, 100);
  ellipse(490, 400, 100, 100);
  if (mousePressed == true && mouseY >= 90 && mouseY <= 190 && mouseX >= 440 && mouseX <= 540) {
      fill(255,0,0);
      ellipse(490, 140, 100, 100);
}
}

I expected for the first ellipse to change colors due to me changing the value of the first made fill that was used to color the first ellipse in

Ackdari :

What about using if-else for choosing the color, like:

void draw() {
    fill(0,0,0);
    if (mousePressed == true && mouseY >= 90 && mouseY <= 190 && mouseX >= 440 && mouseX <= 540) {
        fill(255,0,0);
        ellipse(490, 140, 100, 100);
        fill(0,0,0);
    } else {
        ellipse(490, 140, 100, 100);
    }

    ellipse(490, 400, 100, 100);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=327259&siteId=1