/*Jeremy Turner (JOT) Assignment A2-12 #200024742 Create a button that changes the color of the background when it is clicked.*/ //Although Pooya showed me during office hours how to do this... //for some reason, I cannot seem to make the entire area... //of my button active... int x = 11; int y = 11; int w = 333; int h = 333; //w = width (connects with X axis of shape) //h - height (connects with Y axis of shape) void setup () { size (666, 666); } void draw () { smooth (); strokeWeight(10); //this border makes the square... //...look more like a button. PFont font; font = loadFont("FrenchScriptMT-48.vlw"); //I uploaded this font using the "create font" feature... //The font is a bit corny but it seems to make all of the... //string characters visible... textFont(font); String s = "click on this square!!"; //this is the text that appears on the screen. fill(0,255, 104); //Sets the colour of the text and the square. text(s, 100, 370, 70, 70); //Sets the position of the text myButton(); //here is where I draw up my button... //that was previous stored in the function call //...below... } void myButton () //this is the function call that defines... //the properties of my button... { rect(x,y,w,h); //draws a rectangle according to the ints set above... } void mousePressed () { if (mouseX >= 11 && mouseX <=333 && mouseY >=11 && mouseY <=333) // This defines where on the X and Y axis the active button //...region is...the background changes once it the mouse button //...has been released. { background (random(100), random (100), random (100)); //I have decided to limit the random colour palette... //in order to produce a better colour contrast. } }