run the code and see, IDK why but the rectangle position is so weird, I tried to make a button and make it in the middle but for some reason, it won’t work
int rectSizeX = 300,rectSizeY = 250; // X and Y size of rect
int rectX = width/2;
int rectY = height/2; // Position of square button
color rectHighlight;
color currentColor, rectColor ,baseColor;
boolean rectOver = false;
void setup()
{
fullScreen();
rectMode(CENTER);
buttonSetup();
}
void draw()
{
background(0);
fill(0);
MainButtom();
update();
if (resetPressed()){ rect(400,400,400,400);}
}
void buttonSetup(){
rectColor = color(200);
rectHighlight = color(130);
baseColor = color(102);
currentColor = baseColor;
}
void MainButtom() {
if (rectOver) {
fill(rectHighlight);
} else {
fill(rectColor);
}
stroke(102);
rect(rectX, rectY, rectSizeX, rectSizeY);
}
void update() {
if ( overRect(rectX, rectY, rectSizeX, rectSizeY) ) {
rectOver = true;
} else {
rectOver = false;
}
}
boolean overRect(int x, int y, int x2, int y2) {
if (mouseX >= x-x2/2 && mouseX <= x+x2/2 &&
mouseY >= y-y2/2 && mouseY <= y+y2/2) {
return true;
} else {
return false;
}
}
boolean resetPressed() {
if (mousePressed && rectOver == true) {
return true;
} else {
return false;
}
}