Example
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 3-6: Interactive Zoog?
void setup() {
  // Set the size of the window
  size(200,200);  
  smooth();
  // The frame rate is set to 30 frames per second.
  frameRate(30);
}

void draw() {
  // Draw a white background
  background(255);  
  
  // Set ellipses and rects to CENTER mode
  ellipseMode(CENTER);
  rectMode(CENTER); 
  
  // Draw Zoog's body
  stroke(0);
  fill(175);
  rect(mouseX,mouseY,20,100);

  // Draw Zoog's head
  stroke(0);
  fill(255);
  ellipse(mouseX,mouseY-30,60,60); 

  // Draw Zoog's eyes
  // The eye color is determined by the mouse location.
  fill(mouseX,0,mouseY); 
  ellipse(mouseX-19,mouseY-30,16,32); 
  ellipse(mouseX+19,mouseY-30,16,32); 

  // Draw Zoog's legs
  stroke(0);
  // The legs are drawn according to the mouse location and the previous mouse location.
  line(mouseX-10,mouseY+50,pmouseX-10,pmouseY+60);
  line(mouseX+10,mouseY+50,pmouseX+10,pmouseY+60);
}

void mousePressed() {
  println("Take me to your leader!"); 
}
  • mm

    It might be a very silly question but I was wondering why in this lines:

    // Draw Zoog’s legs
    stroke(0);
    // The legs are drawn according to the mouse location and the previous mouse location.
    line(mouseX-10,mouseY+50,pmouseX-10,pmouseY+60);
    line(mouseX+10,mouseY+50,pmouseX+10,pmouseY+60);

    pmouseX has the same numerical value as mouseX but pmouseY doesn’t?

  • http://www.learningprocessing.com Daniel Shiffman

    This is just an arbitrary way to draw the legs that makes them longer (vertically) as you move the mouse. But there are plenty of other ways you could draw them!