//// square peg round hole //// g. craig hobbs //// 03.02.08 int h = 100; // button height int w = 100; // button width int xc = 200; // x of center of button int yc = 200; // 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, 400); background(0); frameRate(10); cursor(); PFont font; // declare var font = loadFont("AGaramondPro-Regular-24.vlw"); // load the font textFont(font); // set current font } // draw screen void draw(){ PImage b; b = loadImage("circle.jpg"); // round hole background(b); drawB(); if (( keyPressed == true ) && ( key == 's' )) { String s = "Square Peg Round Hole"; // text string text(s, 30, 350, 300, 50); } } boolean active(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 ) && ( active(mouseX, mouseY) == true)) { fill(247, 53, 61); // red } else { fill(0); // blue } noStroke(); rect(mouseX - h/2, mouseY - w/2, h, w); // square peg } //// end