class BUTTONS { int x; int y; int xOrginal; int yOrginal; String string; color mouseOut; color mouseOver; int buttonHeight; int buttonLength; int returnValue; boolean buttonMoved = false; BUTTONS (int xTEMP, int yTEMP, String stringTEMP, color mouseOutTEMP, color mouseOverTEMP, int buttonHeightTEMP, int buttonLengthTEMP, int returnValueTEMP) { xOrginal = xTEMP; x = xOrginal; yOrginal = yTEMP; y = yOrginal; string = stringTEMP; mouseOut = mouseOutTEMP; mouseOver = mouseOverTEMP; buttonHeight = buttonHeightTEMP; buttonLength = buttonLengthTEMP; returnValue = returnValueTEMP; } void position(){ if (((mouseX>=x)&&(mouseX<=x+buttonLength))&&((mouseY>=y)&&(mouseY<=y+buttonHeight))){ if (buttonMoved == false){ x+=3; y+=3; buttonMoved = true; } } else{ x=xOrginal; y=yOrginal; buttonMoved = false; } } void returnPosition(){ x=xOrginal; y=yOrginal; buttonMoved = false; } void function(){ if (((clickedMouseX>=x)&&(clickedMouseX<=x+buttonLength)&&(clickedMouseY>=y)&&(clickedMouseY<=y+buttonHeight)&&(mouseX>=x)&&(mouseX<=x+buttonLength)&&(mouseY>=y)&&(mouseY<=y+buttonHeight))){ backgroundPointer = returnValue; } } void display(){ if (((mouseX>=x)&&(mouseX<=x+buttonLength))&&((mouseY>=y)&&(mouseY<=y+buttonHeight))){ fill(mouseOver); } else { fill(mouseOut); } stroke(0); rect(x,y,buttonLength,buttonHeight); } } color [] colours; BUTTONS [] buttons; int backgroundPointer; int clickedMouseX; int clickedMouseY; void setup(){ size (800,200); colours = new color [4]; colours [0] = color(122,0,0); colours [1] = color(0,122,0); colours [2] = color(0,0,122); colours [3] = color(122,122,0); float randomPointer; randomPointer = random(4); backgroundPointer = int(randomPointer); buttons = new BUTTONS [4]; buttons [0] = new BUTTONS(0,0,"hello", color (200,0,0), color (255,0,0), 50, 100, 0); buttons [1] = new BUTTONS(110,0,"hello", color (0,200,0), color (0,255,0), 50, 100, 1); buttons [2] = new BUTTONS(220,0,"hello", color (0,0,200), color (0,0,255), 50, 100, 2); buttons [3] = new BUTTONS(330,0,"hello", color (200,200,0), color (255,255,0), 50, 100, 3); } void draw(){ background(colours[backgroundPointer]); for (int i=0; i<4; i++){ buttons [i].display(); } } void mousePressed(){ clickedMouseX = mouseX; clickedMouseY = mouseY; for (int i=0; i<4; i++){ buttons[i].position(); } } void mouseReleased(){ for (int i=0; i<4; i++){ buttons [i].function(); buttons[i].returnPosition(); } } void mouseClicked(){ clickedMouseX = mouseX; clickedMouseY = mouseY; for (int i=0; i<4; i++){ buttons [i].function(); buttons [i].returnPosition(); } }