Change background colour with a map

please format code with </> button * homework policy * asking questions

Hi everyone!
I have a code where the abckground color right now changes ray values when I move my mouse. I want it to change in colour though, but somehow I can get it to work so that I can insert my 3 color values. Do I need to change anything somewhere else or is it just npot possible to get away from the grayscale in that form?
Thanks so much in advance!

void setup()
{ size(700, 820); }

void draw()

{ if (mousePressed) {
{
fill(90); } fill(92, 90, 153);
ellipse(mouseX, mouseY, 90, 90); }
else { fill(map(mouseX, 0, width, 54, 200), 15);
rect(0, 0, width, height);
fill(102, 20, 453);
strokeWeight(1);
ellipse(mouseX, mouseY, 60, 60);
strokeWeight(10);
stroke(300, 100, 4);
line(150, 25, mouseX, mouseY);
}}

void mousePressed() {
background(10, 90, 123);
}

Please use Ctrl+t in processing ide to format the code before you copy it to discource. I think it improves your changes to get answers.

void setup()
{
  size(700, 820);
}

void draw()

{
  if (mousePressed) {
    {
      fill(90);
    }
    fill(92, 90, 153);
    ellipse(mouseX, mouseY, 90, 90);
  } else {
    fill(map(mouseX, 0, width, 54, 200), 15);
    rect(0, 0, width, height);
    fill(102, 20, 453);
    strokeWeight(1);
    ellipse(mouseX, mouseY, 60, 60);
    strokeWeight(10);
    stroke(300, 100, 4);
    line(150, 25, mouseX, mouseY);
  }
}

void mousePressed() {
  background(10, 90, 123);
}

2 Likes

And please, don’t feel that I’m picking on you. There shouldn’t be any unformated code, but it happens all the time and it starts to irritate.

1 Like

ahh thank you so much I’m new to this so I didn’t know how to format it!!

So fill has three different forms, 1) grayscale with single value, 2) rgb or hsb with three values and 3) rgba or hsba with four value.
Second is easiest for colour changes. If you want to change colour hue then hsb is your choice.
To use HSB (Hue, Saturation and Brightness) you need to set colorMode() to use HSB, like colorMode(360,100,100). You can choose the range of values. With SB I would use values in range of 40-60 and let H change by mapping from mouse values.