Hex color fill()

Hi! I want the circle to be filled with hex colors depending on the quadrant where the mouse is located, but I don’t know what variables to put in the function drawCircle(), the program only works with RGB. so, what should I enter in the brackets from drawCircle() and fill()?

void setup() {
size(1200, 600);
 background(200);
}
  
void draw(){
   if(mouseX > width/2)
      if(mouseY >height/2) drawCircle(#DB6C6C);
                      else drawCircle(#84D4DE);
   else if(mouseY> height/2) drawCircle(#2E3DBF);
                    else drawCircle(#FDFF95);
}                     
 void drawCircle(int r,int g, int b){
 stroke (0);
  circle (mouseX,mouseY,60);
  fill(r,g,b);
}

Hi @add,

if you really need to do it with that kind of color notation values, you can do it like that …
(Also, the fill needs to be set before using it)

Cheers
— mnse

void setup() {
  size(1200, 600);
  background(200);
}

void draw() {
  if (mouseX > width/2)
    if (mouseY >height/2) drawCircle(#DB6C6C);
    else drawCircle(#84D4DE);
  else if (mouseY> height/2) drawCircle(#2E3DBF);
  else drawCircle(#FDFF95);
}                     

void drawCircle(color col) {
  stroke (0);
  fill(col); // set before circle call
  circle (mouseX, mouseY, 60);
}

Further info about fill …

2 Likes

Hello @add ,

Your function is expecting 3 variables for color:

This will work:

drawCircle(0xDB, 0x6C, 0x6C); 

You can simplify and just pass one variable for color.

There are lots of resources (references, examples, tutorials) here:
https://processing.org/

I encourage you to explore this resources!
You will learn a lot along the way.

References:

That is just one… there are a a lot more resources for color.

:)

1 Like