xxxxxxxxxx
// Program Design Exercise
// Using functions with parameters
function setup() {
createCanvas(400, 200);
background(220);
}
function draw() {
button1();
button2();
}
function button1() {
rectMode(CENTER);
strokeJoin(BEVEL);
strokeWeight(5);
stroke(0); // black
rect(100, 80, 90, 50);
if (mouseX > 60 && mouseX < 140 &&
mouseY > 60 && mouseY < 100) {
fill('red');
} else {
fill('white');
}
strokeJoin(MITER);
stroke(150);
rect(100, 80, 80, 40);
strokeWeight(1);
fill(0);
stroke(0); // black
textAlign(CENTER, CENTER);
text("BACK", 100, 80);
}
function button2() {
rectMode(CENTER);
strokeJoin(BEVEL);
strokeWeight(5);
stroke(0); // black
rect(300, 120, 90, 50);
if (mouseX > 260 && mouseX < 340 &&
mouseY > 100 && mouseY < 140) {
fill('yellow');
} else {
fill('white');
}
strokeJoin(MITER);
stroke(150);
rect(300, 120, 80, 40);
strokeWeight(1);
fill(0);
stroke(0); // black
textAlign(CENTER, CENTER);
text("FORWARD", 300, 120);
}