Create a program that will create a square and fill it with a certain color based on the x and y location of the mouse. Use the mouseMoved () function and create appropriate if statements using the appropriate condition and boolean logic operator to create the square and fill it with a color. The sketch should contain a setup (),draw () as well as the mouseMoved() function . The background will be set to black and will change to the appropriate color when the mouse enters the area specified by the condition. All other areas will remain black.
color c1;
// Add more colors for each rectangle
void setup()
{
size (400, 400);
background (0);
}
void draw()
{
fill(c1);
rect(0, 0, 200, 200);
// 3 more rectangles required
}
void mouseMoved()
{
println(mouseX, mouseY); //Displays mouse location
// 4 conditional statements to check for location of mouseX and mouseY
// These conditions when true set the 4 colors for the 4 rectangles
}
This is what I have now. It draws the rectangles all at once. I’m trying to get it to move the rectangles when I move the mouse and only show one color at a time.
Any advice?
(create appropriate if statements using the appropriate condition and boolean logic operator to create the square and fill it with a color)
void setup()
{size (400, 400);
background (0);}
color c1=color(255, 255, 0);
color c2=color(255, 0, 0);
color c3=color(0, 0, 255);
color c4=color(0, 255, 0);
int value = 0;
void draw()
{
fill(c1);
rect(0, 0, 200, 200);
fill(c2);
rect(200, 0, 200, 200);
fill(c3);
rect(0, 200, 200, 200);
fill(c4);
rect(200, 200, 200, 200);
}
void mouseMoved()
{
}