Dear
As a beginner, I wanted to create 4 buttons that show different colors when being pressed, however, when I press each of them they don’t work individually. Additionally, I have a serious problem with writing distances for them. In fact, I’m not sure about the distances I’ve written for each of them. Needless to say, conditionals have been written in mousePressed event haven’t been completed yet.
may I ask you to help me?
color colA = color(255,0,0);
color colB = color(0,255,0);
color colC = color(0,0,255);
color colD = color(70,0,255);
float colSwitch = 0;
float positionX1 = 150;
float positionX2 = 380;
float positionX3 = 610;
float positionY1 = 150;
float positionY2 = 380;
float positionY3 = 610;
void setup()
{
size(760,760);
}
void draw()
{
background(0);
rect(positionX1,positionY1,230,230);
rect(positionX2,positionY1,230,230);
rect(positionX1,positionY2,230,230);
rect(positionX2,positionY2,230,230);
if(colSwitch==0)
{ fill(colA);
}else if(colSwitch==1)
{ fill(colB);
}
}
void mousePressed()
{
float d1 = dist(positionX1,positionY1,mouseX,mouseY);
float d2 = dist(positionX2,positionY1,mouseX,mouseY);
float d3 = dist(positionX1,positionY2,mouseX,mouseY);
float d4 = dist(positionX2,positionY2,mouseX,mouseY);
if(positionX1<d1 && d1<positionX2 && positionY1<d1 && d1<positionY2)
{
if(colSwitch==0)
{ colSwitch = 1;
}else if(positionX2<d2 && d2<positionX3 && positionY1<d2 && d2<positionY2 )
{ colSwitch = 2;
}
}
}