int width = 800; int height = 600; int button1X; int button1Y; int button1Width = width/20; int button1Height = height/20; int button2X; int button2Y; int button2Width = button1Width; int button2Height = button1Height; float buttonFont = button1Height/1.5; float wordFont = button1Height; int angle = 0; color buttonColor, buttonHighlight, buttonPressed; PFont font; boolean button1Over = false; boolean button2Over = false; void setup() { size(width,height); smooth(); font = loadFont("CourierNew36.vlw"); buttonColor = color(255); buttonHighlight = color(200); buttonPressed = color(50); button1X = width/10 - button1Width/2; button1Y = height/5 - button1Height/2; button2X = 2*width/10 - button1Width/2; button2Y = height/5 - button1Height/2; } void draw() { update(mouseX,mouseY); background(0); if(button1Over) { fill(buttonHighlight); } else { fill(buttonColor); } stroke(0); rect(button1X,button1Y, button1Width, button1Height); if(button2Over) { fill(buttonHighlight); } else { fill(buttonColor); } stroke(0); rect(button2X,button2Y, button2Width, button2Height); textFont(font, buttonFont); fill(0); text("-1",button1X + button1Width/3.9,button1Y + button1Height/1.3); text("+1",button2X + button1Width/3.9,button1Y + button1Height/1.3); textFont(font, wordFont); fill(255); text("Inner Angle: " + angle,button2X + button1Width + width/20,button1Y + button1Height/1.2); } /////////////////////////////////// void update(int x, int y) { if(overButton(button1X,button1Y,button1Width,button1Height)){ button1Over = true; } else { button1Over = false; } if(overButton(button2X,button2Y,button2Width,button2Height)){ button2Over = true; } else { button2Over = false; } } void mousePressed() { if(button1Over) { println("Button1 pressed"); angle = angle - 1; fill(buttonPressed); rect(button1X,button1Y, button1Width, button1Height); } if(button2Over) { println("Button2 pressed"); angle = angle + 1; fill(buttonPressed); rect(button2X,button2Y, button2Width, button2Height); } } boolean overButton(int x, int y, int width, int height) { if(mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } }