// Draw Zoog. This version of Zoog follows // the mouse pointer. The draw() method // repeatedly redraws Zoog centered over // the location onscreen where the cursor // points. int headRed = 255; int headGreen = 255; int headBlue = 255; void setup () { size(300,300); // Draw ellipses and rectangles by specifying their center and dimensions ellipseMode(CENTER); rectMode(CENTER); smooth(); } void draw () { background(175, 190, 75); // Draw Zoog's body stroke(0); fill(150); rect(mouseX,mouseY,20,100); // Draw Zoog's head fill(headRed, headGreen, headBlue); ellipse(mouseX,mouseY-30,60,60); // Draw Zoog's eyes fill(0); ellipse(mouseX-19,mouseY-30,16,32); ellipse(mouseX+19,mouseY-30,16,32); // Draw Zoog's legs stroke(0); line(mouseX-10,mouseY+50,mouseX-20,mouseY+60); line(mouseX+10,mouseY+50,mouseX+20,mouseY+60); // Whenever the user presses the (left) mouse // button, Zoog's head changes color. If the // user releases the button, Zoog's head // slowly fades to white. // // mousePressed() (with the parentheses) is a // function that is called whenever the user // clicks on the mouse button. mousePressed // (without the parentheses) is a variable that // is true only if the user is holding down the // mouse button if (mousePressed == false) { // Pure white, in RGB color, means that red, // green, and blue are all 255. If we add 1 to // each value repeatedly, all three will // eventually reach 1. headRed = headRed + 1; headGreen = headGreen + 1; headBlue = headBlue + 1; } } void mousePressed () { // When mouse is clicked, change Zoog's head // to a random color. // // The random() method takes an int n as its // argument (input). It returns a random # in // the range 0-(n-1) (for example, random(5) // returns a value between 0 and 4 inclusive). // random() returns a floating-point value, so // we have to cast it to an int before we can // assign it as a color component. headRed = int(random(256)); headGreen = int(random(256)); headBlue = int(random(256)); }