//exercise 5-5 simple rollover using logical operators //int x = 50; //int y = 50; //int w = 100; //int h = 75; // //void setup() { // size(400,400); //} // //void draw() { // background(0); // stroke(255); // if(mouseX > 50 && mouseY > 50 && mouseX < 150 && mouseY < 125) { // fill(255); // } // else { // fill(0); // } // rect(x,y,w,h); //} class Button { //Button location and size float x; float y; float w; float h; boolean on; //is it on or off? Button(float x_, float y_, float w_, float h_) { x = x_; y = y_; w = w_; h = h_; on = false; //button starts as off } void click(int mx, int my) { //initiate two new local variables for mouse location //check to see if mouse is inside rectangle if (mx > x && mx < x+w && my > y && my < y+h) { on = !on; //not on - ! means "not" } } //draw button void display() { //rectMode(CORNER); stroke(0); //color changes based on button state if (on) { fill(#DE0D0D); } else { fill (0); } rect(x, y, w, h); } }