//// 080216b cr by rha on thales2 with P 0135 beta //// follow R&F handbook p. 212, mouse buttons // get some variables (dimensions of our angle) int h = 30; // button height int w = 40; // button width int xc = 200; // x of center of button int yc = 150; // y of center int xmin = xc - w/2; // left edge of button int xmax = xc + w/2; // right edge int ymin = yc - h/2; // top edge int ymax = yc + w/2; // bottom // setup the canvas void setup(){ size(400, 300); // do not want to change this later background(0); // black is nice for a movie/} frameRate(10); // slow // noLoop(); // sometimes useful // print("starting"); } // draw something void draw(){ background(0); drawB(); // draw my button } boolean hot(int x, int y) { boolean temp = false; if (( x > xmin ) && ( x < xmax ) && ( y > ymin) && ( y < ymax )) { temp = true; } return temp; } // here is the button code void drawB() { if (( mousePressed == true ) && ( hot(mouseX, mouseY) == true)) { fill(255, 0, 0); // red } else { background(128); // gray fill(0, 255, 0); // green } noStroke(); rect(200 - w/2, 150 - h/2, w, h); // our button } //// end