add
November 30, 2022, 9:30am
1
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);
}
mnse
November 30, 2022, 11:03am
2
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 …
Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color …
2 Likes
glv
November 30, 2022, 11:54am
3
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