Hi all¡
I am trying to add colours to 4 rectangles on the screen. To dod that I am learning how to create my own functions so i will use the distance from some of this rectangle to the mouseX and mouseY coordinates to add variable colour for them…i cant understand why it only appears color in one rectangle…someone can help me please? I put here the code
void setup() {
size(640, 320);
}
void draw() {
background(0);
//TOP LEFT SQUARE
fill(distance(0, 0, mouseX, mouseY));
rect(0, 0, width/2-1, height/2-1);
//TOP RIGHT SQUARE
fill(distance(width, 0, mouseX, mouseY));
rect(width/2, 0, width/2-1, height/2-1);
//BOTTOM LEFT SQUARE
fill(distance(0, height, mouseX, mouseY));
rect(0, height/2, width/2-1, height/2-1);
//BOTTOM RIGHT SQUARE
fill(distance(width, height, mouseX, mouseY));
rect(width/2, height/2, width/2-1, height/2-1);
}
float distance(float x1, float x2, float y1, float y2) {
float dx=x1-x2;
float dy=y1-y2;
float d=sqrt(dxdx+dydy);
return d;
}
THANKS
JAVIER