xxxxxxxxxx
77
let button1X, button1Y, button1Width, button1Height; //variables for button 1
let button2X, button2Y, button2Width, button2Height; //variables for button 2
let button3X, button3Y, button3Width, button3Height; //variables for button 3
let currentPage = 1; //initialize the current page to 1
function setup() {
createCanvas(windowWidth, windowHeight);
// button 1 size and placement
button1Width = 200;
button1Height = 100;
button1X = width / 2 - button1Width / 2;
button1Y = height / 2 - button1Height / 2 - 50;
// button 2 size and placement
button2Width = 200;
button2Height = 100;
button2X = width / 2 - button2Width / 2;
button2Y = height / 2 + button2Height / 2 + 50;
// button 3 size and placement
button3Width = 100;
button3Height = 50;
button3X = width / 2 - button3Width / 2;
button3Y = height - button3Height - 50;
}
function draw() {
background(0);
if (currentPage == 1) {
//if the current page is 1, draw the buttons for page 1
fill(255);
rect(button1X, button1Y, button1Width, button1Height);
rect(button2X, button2Y, button2Width, button2Height);
} else if (currentPage == 2) {
//if the current page is 2, draw the button for page 2
fill(255);
rect(button3X, button3Y, button3Width, button3Height);
}
}
function mouseClicked() {
if (currentPage == 1) {
//if the current page is 1
if (
mouseX > button1X &&
mouseX < button1X + button1Width &&
mouseY > button1Y &&
mouseY < button1Y + button1Height
) {
//if button 1 is clicked
currentPage = 2; //change the current page to 2
} else if (
mouseX > button2X &&
mouseX < button2X + button2Width &&
mouseY > button2Y &&
mouseY < button2Y + button2Height
) {
//if button 2 is clicked
currentPage = 2; //change the current page to
}
} else if (currentPage == 2) {
//if the current page is 2
if (
mouseX > button3X &&
mouseX < button3X + button3Width &&
mouseY > button3Y &&
mouseY < button3Y + button3Height
) {
//if button 3 is clicked
currentPage = 1; //change the current page back to 1
}
}
}