Hi there! could someone please fix my code? (interactive face)

edited February 2016 in Library Questions

He wants us to organize it using drawFace(); checkNose(); checkMouth(); checkEyes(); Could someone lease integrate this into my code? For now, please comment out the audio (minim)

        import ddf.minim.*;
        Minim minim;
        AudioPlayer song;
        AudioPlayer song2;
        AudioPlayer song3;

        float open = 10;
        float diameter;
        color c = 255;
        color eyecolour = 255;


        void setup() {
          size(800, 800);
          diameter = width/4;
          minim = new Minim(this);
          song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
          song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
          song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
        }

        void draw() {
          background(255);//white background
          //drawFace()
          //checkNose();
          //checkMouth();
          //checkEyes();
          //checkHair();

          //  void drawFace();
          fill(237, 255, 3);//yellow colour
          ellipse(400, 400, 600, 600);//draws the yellow circle of the face
          fill(0);//colour of hair

          line(283, 156, 369, 208);//draws left eyebrow
          line(507, 156, 417, 209);//draw right eyebrow
          line(147, 239, 93, 74);
          line(93, 74, 199, 178);
          line(199, 178, 220, 29);
          line(220, 29, 301, 117);
          line(301, 117, 330, 25);
          line(330, 25, 371, 102);
          line(371, 102, 424, 28);
          line(424, 28, 455, 105);
          line(455, 105, 531, 39);
          line(531, 39, 549, 140);
          line(549, 140, 641, 51);
          line(641, 51, 623, 199);//draws hair, left to right
          //println(mouseX, mouseY);

          float d = pythagorean(mouseX, mouseY, width/3, height/3);
          float e = pythagorean(mouseX, mouseY, width/1.5, height/3);

          float g = pythagorean(mouseX, mouseY, width/2, height/2);

          // click

          if (g<0.5*diameter/2 && mousePressed) {
            c=color(random(255), random(255), random(255));
            song.play();  //boing sound when you click on the nose
          } else if (g<0.5*diameter/2) {
            c=color(0, 255, 0);//hover over nse, chnage colour to green
          } else {
            c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
          }// All of this coding is to change the colour of the nose when you hover over/press it



          fill(c);

          ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
          fill(eyecolour);
          ellipse(width/3, height/3, diameter, diameter);//draws left eye
          fill(random(255), random(255), random(255));//colour of pupils
          ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
          fill(eyecolour);//colour of eyes
          ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
          fill(random(255), random(255), random(255));//colour of pupil 
          ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye

          if (d<diameter/2 || e<diameter/2) {
            eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
            fill(eyecolour);
            ellipse(width/3, height/3, diameter, diameter);
            ellipse(width/1.5, height/3, diameter, diameter);
            line(168, 280, 365, 280);//line inside left eye when mouse hovers over
            line(435, 280, 630, 280);//line inside right eye when mouse hovers over
            song3.play();
          } else {
            eyecolour=color(255);//keep colour as white
          }


          fill(255, 0, 0);
          ellipse(400, 600, 300, open);//draws mouth



          //opening mouth 
          if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
            mousePressed = false;
            open = 200;//mouth open and close
          }

          if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
            mousePressed = false;//mouth open and close
            open = 10;
            song2.play();//slurping sound when you click on the mouth
          }
        }


        float pythagorean (float mx, float my, float cx, float cy) {
          float dx = (mx-cx);
          float dy = (my-cy);
          float d = sqrt( pow(dx, 2)+pow(dy, 2) );
          return d;
        }
Tagged:

Answers

  • Please comment out music statements as those already work

  • Edit your post. Select your code. Press Ctrl + o.

    No one is going to help you until you post properly formatted code. We aren't even going to look at it.

  • Thanks TfGuy44. tbh i actually had no idea about that but it seems a lot neater. Thank you!

  • I made a function drawFace() and showed you how to use it.

    I am sure, you can now make the other functions yourself

    import ddf.minim.*;
    Minim minim;
    AudioPlayer song;
    AudioPlayer song2;
    AudioPlayer song3;
    
    float open = 10;
    float diameter;
    color c = 255;
    color eyecolour = 255;
    
    
    void setup() {
      size(800, 800);
      diameter = width/4;
      minim = new Minim(this);
      song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
      song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
      song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
    }
    
    void draw() {
      background(255);//white background
      //drawFace()
      //checkNose();
      //checkMouth();
      //checkEyes();
      //checkHair();
    
      //  draw Face 
      drawFace(); 
    
      float d = pythagorean(mouseX, mouseY, width/3, height/3);
      float e = pythagorean(mouseX, mouseY, width/1.5, height/3);
    
      float g = pythagorean(mouseX, mouseY, width/2, height/2);
    
      // click
    
      if (g<0.5*diameter/2 && mousePressed) {
        c=color(random(255), random(255), random(255));
        song.play();  //boing sound when you click on the nose
      } else if (g<0.5*diameter/2) {
        c=color(0, 255, 0);//hover over nse, chnage colour to green
      } else {
        c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
      }// All of this coding is to change the colour of the nose when you hover over/press it
    
    
    
      fill(c);
    
      ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
      fill(eyecolour);
      ellipse(width/3, height/3, diameter, diameter);//draws left eye
      fill(random(255), random(255), random(255));//colour of pupils
      ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
      fill(eyecolour);//colour of eyes
      ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
      fill(random(255), random(255), random(255));//colour of pupil 
      ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye
    
      if (d<diameter/2 || e<diameter/2) {
        eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
        fill(eyecolour);
        ellipse(width/3, height/3, diameter, diameter);
        ellipse(width/1.5, height/3, diameter, diameter);
        line(168, 280, 365, 280);//line inside left eye when mouse hovers over
        line(435, 280, 630, 280);//line inside right eye when mouse hovers over
        // song3.play();
      } else {
        eyecolour=color(255);//keep colour as white
      }
    
      fill(255, 0, 0);
      ellipse(400, 600, 300, open);//draws mouth
    
    
      //opening mouth 
      if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
        mousePressed = false;
        open = 200;//mouth open and close
      }
    
      if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
        mousePressed = false;//mouth open and close
        open = 10;
        song2.play();//slurping sound when you click on the mouth
      }
    }// draw 
    
    // ------------------------------
    
    void drawFace() {
      fill(237, 255, 3);//yellow colour
      ellipse(400, 400, 600, 600);//draws the yellow circle of the face
      fill(0);//colour of hair
    
      line(283, 156, 369, 208);//draws left eyebrow
      line(507, 156, 417, 209);//draw right eyebrow
      line(147, 239, 93, 74);
      line(93, 74, 199, 178);
      line(199, 178, 220, 29);
      line(220, 29, 301, 117);
      line(301, 117, 330, 25);
      line(330, 25, 371, 102);
      line(371, 102, 424, 28);
      line(424, 28, 455, 105);
      line(455, 105, 531, 39);
      line(531, 39, 549, 140);
      line(549, 140, 641, 51);
      line(641, 51, 623, 199);//draws hair, left to right
      //println(mouseX, mouseY);
    } // end of drawface
    
    float pythagorean (float mx, float my, float cx, float cy) {
      float dx = (mx-cx);
      float dy = (my-cy);
      float d = sqrt( pow(dx, 2)+pow(dy, 2) );
      return d;
    }
    
  • pythagorean

    Look at dist() in the reference

  • edited February 2016

    Thank you so much! But for some reason, when I did checkNose(); , it doesn't work. I did it the exact same when you had done "drawFace();".

    import ddf.minim.*;
    Minim minim;
    AudioPlayer song;
    AudioPlayer song2;
    AudioPlayer song3;
    
    float open = 10;
    float diameter;
    color c = 255;
    color eyecolour = 255;
    
    
    void setup() {
      size(800, 800);
      diameter = width/4;
      minim = new Minim(this);
      song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
      song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
      song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
    }
    
    void draw() {
      background(255);//white background
      //drawFace()
      //checkNose();
      //checkMouth();
      //checkEyes();
      //checkHair(); 
      drawFace(); 
      checkNose();
    
    
    
      float d = pythagorean(mouseX, mouseY, width/3, height/3);
      float e = pythagorean(mouseX, mouseY, width/1.5, height/3);
    
      float g = pythagorean(mouseX, mouseY, width/2, height/2);
    
      // click
     void checkNose() {
      if (g<0.5*diameter/2 && mousePressed) {
        c=color(random(255), random(255), random(255));
        song.play();  //boing sound when you click on the nose
      } else if (g<0.5*diameter/2) {
        c=color(0, 255, 0);//hover over nse, chnage colour to green
      } else {
        c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
      }// All of this coding is to change the colour of the nose when you hover over/press it
    
     }
    
      fill(c);
    
      ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
      fill(eyecolour);
      ellipse(width/3, height/3, diameter, diameter);//draws left eye
      fill(random(255), random(255), random(255));//colour of pupils
      ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
      fill(eyecolour);//colour of eyes
      ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
      fill(random(255), random(255), random(255));//colour of pupil 
      ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye
    
      if (d<diameter/2 || e<diameter/2) {
        eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
        fill(eyecolour);
        ellipse(width/3, height/3, diameter, diameter);
        ellipse(width/1.5, height/3, diameter, diameter);
        line(168, 280, 365, 280);//line inside left eye when mouse hovers over
        line(435, 280, 630, 280);//line inside right eye when mouse hovers over
        // song3.play();
      } else {
        eyecolour=color(255);//keep colour as white
      }
    
      fill(255, 0, 0);
      ellipse(400, 600, 300, open);//draws mouth
    
    
      //opening mouth 
      if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
        mousePressed = false;
        open = 200;//mouth open and close
      }
    
      if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
        mousePressed = false;//mouth open and close
        open = 10;
        song2.play();//slurping sound when you click on the mouth
      }
    }// draw 
    
    
    
    void drawFace() {
      fill(237, 255, 3);//yellow colour
      ellipse(400, 400, 600, 600);//draws the yellow circle of the face
      fill(0);//colour of hair
    
      line(283, 156, 369, 208);//draws left eyebrow
      line(507, 156, 417, 209);//draw right eyebrow
      line(147, 239, 93, 74);
      line(93, 74, 199, 178);
      line(199, 178, 220, 29);
      line(220, 29, 301, 117);
      line(301, 117, 330, 25);
      line(330, 25, 371, 102);
      line(371, 102, 424, 28);
      line(424, 28, 455, 105);
      line(455, 105, 531, 39);
      line(531, 39, 549, 140);
      line(549, 140, 641, 51);
      line(641, 51, 623, 199);//draws hair, left to right
      //println(mouseX, mouseY);
    } // end of drawface
    
    float pythagorean (float mx, float my, float cx, float cy) {
      float dx = (mx-cx);
      float dy = (my-cy);
      float d = sqrt( pow(dx, 2)+pow(dy, 2) );
      return d;
    }
    
  • No no....

    Function checkNose must be outside(!!!) draw()

    After the }

  • edited February 2016

    kk, so i put it outside of the draw but now it's saying that "The operator < is undefined for the argument type(s) PGraphics, float."

        import ddf.minim.*;
        Minim minim;
        AudioPlayer song;
        AudioPlayer song2;
        AudioPlayer song3;
    
        float open = 10;
        float diameter;
        color c = 255;
        color eyecolour = 255;
    
    
        void setup() {
          size(800, 800);
          diameter = width/4;
          minim = new Minim(this);
          song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
          song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
          song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
        }
    
        void draw() {
          background(255);//white background
          //drawFace()
          //checkNose();
          //checkMouth();
          //checkEyes();
          //checkHair(); 
          drawFace(); 
          checkNose();
    
    
    
          float d = pythagorean(mouseX, mouseY, width/3, height/3);
          float e = pythagorean(mouseX, mouseY, width/1.5, height/3);
    
          float g = pythagorean(mouseX, mouseY, width/2, height/2);
    
          // click
    
          fill(eyecolour);
          ellipse(width/3, height/3, diameter, diameter);//draws left eye
          fill(random(255), random(255), random(255));//colour of pupils
          ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
          fill(eyecolour);//colour of eyes
          ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
          fill(random(255), random(255), random(255));//colour of pupil 
          ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye
    
          if (d<diameter/2 || e<diameter/2) {
            eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
            fill(eyecolour);
            ellipse(width/3, height/3, diameter, diameter);
            ellipse(width/1.5, height/3, diameter, diameter);
            line(168, 280, 365, 280);//line inside left eye when mouse hovers over
            line(435, 280, 630, 280);//line inside right eye when mouse hovers over
            // song3.play();
          } else {
            eyecolour=color(255);//keep colour as white
          }
    
          fill(255, 0, 0);
          ellipse(400, 600, 300, open);//draws mouth
    
    
          //opening mouth 
          if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
            mousePressed = false;
            open = 200;//mouth open and close
          }
    
          if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
            mousePressed = false;//mouth open and close
            open = 10;
            song2.play();//slurping sound when you click on the mouth
          }
        }// draw 
    
    
    
        void drawFace() {
          fill(237, 255, 3);//yellow colour
          ellipse(400, 400, 600, 600);//draws the yellow circle of the face
          fill(0);//colour of hair
    
          line(283, 156, 369, 208);//draws left eyebrow
          line(507, 156, 417, 209);//draw right eyebrow
          line(147, 239, 93, 74);
          line(93, 74, 199, 178);
          line(199, 178, 220, 29);
          line(220, 29, 301, 117);
          line(301, 117, 330, 25);
          line(330, 25, 371, 102);
          line(371, 102, 424, 28);
          line(424, 28, 455, 105);
          line(455, 105, 531, 39);
          line(531, 39, 549, 140);
          line(549, 140, 641, 51);
          line(641, 51, 623, 199);//draws hair, left to right
          //println(mouseX, mouseY);
        } // end of drawface
    
        void checkNose() {
          if (g<0.5*diameter/2 && mousePressed) {
            c=color(random(255), random(255), random(255));
            song.play();  //boing sound when you click on the nose
          } else if (g<0.5*diameter/2) {
            c=color(0, 255, 0);//hover over nose, chnage colour to green
          } else {
            c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
          }// All of this coding is to change the colour of the nose when you hover over/press it
    
         }
         {
          fill(c);
    
          ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
         }
        float pythagorean (float mx, float my, float cx, float cy) {
          float dx = (mx-cx);
          float dy = (my-cy);
          float d = sqrt( pow(dx, 2)+pow(dy, 2) );
          return d;
        }
    
  • Not sure what's going on (not on my Computer)

    Hit ctrl-t to see the indents....

    also when you set g you must do so in checkNose and not in draw()

  • When you say "set g", do you mean i should move the float g = pythagorean(mouseX, mouseY, width/2, height/2); down to the checkNose section?

    and also, should i add

    return e;
    return g;
    

    at the end of my code as well or is it not necessary?

  • Yes.

    2nd question: try

  • kk, and so when i did that, I'm getting a "NullPointerException" on line 115; fill(c) of my code.

  • Are we sure that 115 is inside checkNose

    The {} look wrong

  • which bracket would i remove then?

  • 113 and 114?

  • hit ctrl-t to auto indent

    then you see if there's stuff outside functions

  • tried that. Nothing's working now, and none of the interaction is occurring :(

  • you'll be able to fix it.

    idea: post the entire code.

    ore are you just whinning?

  • edited February 2016

    Im not whining. But its not working at all.

      import ddf.minim.*;
        Minim minim;
        AudioPlayer song;
        AudioPlayer song2;
        AudioPlayer song3;
    
        float open = 10;
        float diameter;
        color c = 255;
        color eyecolour = 255;
    
    
        void setup() {
          size(800, 800);
          diameter = width/4;
          minim = new Minim(this);
          song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
          song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
          song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
        }
    
        void draw() {
          background(255);//white background
          //drawFace()
          //checkNose();
          //checkMouth();
          //checkEyes();
          //checkHair(); 
          drawFace(); 
          checkNose();
    
    
    
          float d = pythagorean(mouseX, mouseY, width/3, height/3);
          float e = pythagorean(mouseX, mouseY, width/1.5, height/3);
    
    
          // click
    
          fill(eyecolour);
          ellipse(width/3, height/3, diameter, diameter);//draws left eye
          fill(random(255), random(255), random(255));//colour of pupils
          ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
          fill(eyecolour);//colour of eyes
          ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
          fill(random(255), random(255), random(255));//colour of pupil 
          ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye
    
          if (d<diameter/2 || e<diameter/2) {
            eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
            fill(eyecolour);
            ellipse(width/3, height/3, diameter, diameter);
            ellipse(width/1.5, height/3, diameter, diameter);
            line(168, 280, 365, 280);//line inside left eye when mouse hovers over
            line(435, 280, 630, 280);//line inside right eye when mouse hovers over
            // song3.play();
          } else {
            eyecolour=color(255);//keep colour as white
          }
    
          fill(255, 0, 0);
          ellipse(400, 600, 300, open);//draws mouth
    
    
          //opening mouth 
          if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
            mousePressed = false;
            open = 200;//mouth open and close
          }
    
          if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
            mousePressed = false;//mouth open and close
            open = 10;
            song2.play();//slurping sound when you click on the mouth
          }
        }// draw 
    
    
    
        void drawFace() {
          fill(237, 255, 3);//yellow colour
          ellipse(400, 400, 600, 600);//draws the yellow circle of the face
          fill(0);//colour of hair
    
          line(283, 156, 369, 208);//draws left eyebrow
          line(507, 156, 417, 209);//draw right eyebrow
          line(147, 239, 93, 74);
          line(93, 74, 199, 178);
          line(199, 178, 220, 29);
          line(220, 29, 301, 117);
          line(301, 117, 330, 25);
          line(330, 25, 371, 102);
          line(371, 102, 424, 28);
          line(424, 28, 455, 105);
          line(455, 105, 531, 39);
          line(531, 39, 549, 140);
          line(549, 140, 641, 51);
          line(641, 51, 623, 199);//draws hair, left to right
          //println(mouseX, mouseY);
        } // end of drawface
    
        float g = pythagorean(mouseX, mouseY, width/2, height/2);
        void checkNose() {
          if (g<0.5*diameter/2 && mousePressed) {
            c=color(random(255), random(255), random(255));
            song.play();  //boing sound when you click on the nose
          } else if (g<0.5*diameter/2) {
            c=color(0, 255, 0);//hover over nose, chnage colour to green
          } else {
            c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
          }// All of this coding is to change the colour of the nose when you hover over/press it
    
    
          fill (c);
    
          ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
        }
        float pythagorean (float mx, float my, float cx, float cy) {
          float dx = (mx-cx);
          float dy = (my-cy);
          float d = sqrt( pow(dx, 2)+pow(dy, 2) );
    
          return g;
        }
    
  • import ddf.minim.*; 
    Minim minim; 
    AudioPlayer song; 
    AudioPlayer song2; 
    AudioPlayer song3;
    
    
    
    
    float open = 10;
    float diameter;
    color c = 255;
    color eyecolour = 255;
    
    
    void setup() {
      size(800, 800);
      diameter = width/4;
      minim = new Minim(this);
      song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
      song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
      song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
    }
    
    void draw() {
      background(255);//white background
      //drawFace()
      //checkNose();
      //checkMouth();
      //checkEyes();
      //checkHair(); 
      drawFace(); 
      checkNose();
    
    
    
      float d = pythagorean(mouseX, mouseY, width/3, height/3);
      float e = pythagorean(mouseX, mouseY, width/1.5, height/3);
    
    
      // click
    
      fill(eyecolour);
      ellipse(width/3, height/3, diameter, diameter);//draws left eye
      fill(random(255), random(255), random(255));//colour of pupils
      ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
      fill(eyecolour);//colour of eyes
      ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
      fill(random(255), random(255), random(255));//colour of pupil 
      ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye
    
      if (d<diameter/2 || e<diameter/2) {
        eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
        fill(eyecolour);
        ellipse(width/3, height/3, diameter, diameter);
        ellipse(width/1.5, height/3, diameter, diameter);
        line(168, 280, 365, 280);//line inside left eye when mouse hovers over
        line(435, 280, 630, 280);//line inside right eye when mouse hovers over
        song3.play();
      } else {
        eyecolour=color(255);//keep colour as white
      }
    
      fill(255, 0, 0);
      ellipse(400, 600, 300, open);//draws mouth
    
    
      //opening mouth 
      if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
        mousePressed = false;
        open = 200;//mouth open and close
      }
    
      if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
        mousePressed = false;//mouth open and close
        open = 10;
        song2.play();//slurping sound when you click on the mouth
      }
    }// draw 
    
    
    
    void drawFace() {
      fill(237, 255, 3);//yellow colour
      ellipse(400, 400, 600, 600);//draws the yellow circle of the face
      fill(0);//colour of hair
    
      line(283, 156, 369, 208);//draws left eyebrow
      line(507, 156, 417, 209);//draw right eyebrow
      line(147, 239, 93, 74);
      line(93, 74, 199, 178);
      line(199, 178, 220, 29);
      line(220, 29, 301, 117);
      line(301, 117, 330, 25);
      line(330, 25, 371, 102);
      line(371, 102, 424, 28);
      line(424, 28, 455, 105);
      line(455, 105, 531, 39);
      line(531, 39, 549, 140);
      line(549, 140, 641, 51);
      line(641, 51, 623, 199);//draws hair, left to right
      //println(mouseX, mouseY);
    } // end of drawface
    
    
    void checkNose() {
    
      float g = pythagorean(mouseX, mouseY, width/2, height/2);
    
    
    
      if (g<0.5*diameter/2 && mousePressed) {
        c=color(random(255), random(255), random(255));
        //    song.play();  //boing sound when you click on the nose
      } else if (g<0.5*diameter/2) {
        c=color(0, 255, 0);//hover over nose, chnage colour to green
      } else {
        c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
      } // All of this coding is to change the colour of the nose when you hover over/press it
    
    
      fill (c);
    
      ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
    
      //return g;
    }
    
    
    float pythagorean (float mx, float my, float cx, float cy) {
      float dx = (mx-cx);
      float dy = (my-cy);
      float d = sqrt( pow(dx, 2)+pow(dy, 2) );
    
      return d;
    }
    
  • you had this line outside a function...

    float g = pythagorean(mouseX, mouseY, width/2, height/2);
    
  • edited February 2016

    wow okay thank you so much Chris. I finally got everything to work. I really appreciate you helping me out and the rest of the community on Processing. Means a lot.

            import ddf.minim.*; 
            Minim minim; 
            AudioPlayer song; 
            AudioPlayer song2; 
            AudioPlayer song3;
    
    
    
    
            float open = 10;
            float diameter;
            color c = 255;
            color eyecolour = 255;
    
    
            void setup() {
              size(800, 800);
              diameter = width/4;
              minim = new Minim(this);
              song = minim.loadFile("Boing.mp3");//click on nose, boing sound effect
              song2 = minim.loadFile("Slurp.mp3");//open & then close mouth, slurping sound effect
              song3 = minim.loadFile("Ouch.mp3");//hover over eyes, ouch sound effect
            }
    
            void draw() {
              background(255);//white background
              //drawFace()
              //checkNose();
              //checkMouth();
              //checkEyes();
              //checkHair(); 
              drawFace(); 
              checkNose();
              checkMouth();
              checkEyes();
            }
            void drawFace() {
              fill(237, 255, 3);//yellow colour
              ellipse(400, 400, 600, 600);//draws the yellow circle of the face
              fill(0);//colour of hair
    
              line(283, 156, 369, 208);//draws left eyebrow
              line(507, 156, 417, 209);//draw right eyebrow
              line(147, 239, 93, 74);
              line(93, 74, 199, 178);
              line(199, 178, 220, 29);
              line(220, 29, 301, 117);
              line(301, 117, 330, 25);
              line(330, 25, 371, 102);
              line(371, 102, 424, 28);
              line(424, 28, 455, 105);
              line(455, 105, 531, 39);
              line(531, 39, 549, 140);
              line(549, 140, 641, 51);
              line(641, 51, 623, 199);//draws hair, left to right
              //println(mouseX, mouseY);
            } // end of drawface
    
    
            void checkNose() {
    
              float g = pythagorean(mouseX, mouseY, width/2, height/2);
    
    
    
              if (g<0.5*diameter/2 && mousePressed) {
                c=color(random(255), random(255), random(255));
                song.play();  //boing sound when you click on the nose
              } else if (g<0.5*diameter/2) {
                c=color(0, 255, 0);//hover over nose, chnage colour to green
              } else {
                c=color(0, 0, 255);//otherwise, if there is no mouse inside the nose, keep it blue
              } // All of this coding is to change the colour of the nose when you hover over/press it
    
    
              fill (c);
    
              ellipse(width/2, height/2, 0.5*diameter, 0.5*diameter);//location/size of nose
    
              //return g;
            }
            void checkMouth() {
              fill(255, 0, 0);
              ellipse(400, 600, 300, open);//draws mouth
    
    
              //opening mouth 
              if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 10) && (mousePressed == true)) {
                mousePressed = false;
                open = 200;//mouth open and close
              }
    
              if ((mouseX > 370) && (mouseX < 430) && (mouseY > 570) && (mouseY < 630) && (open == 200) && (mousePressed == true)) {
                mousePressed = false;//mouth open and close
                open = 10;
                song2.play();//slurping sound when you click on the mouth
              }
            }// draw 
            void checkEyes() {
              float d = pythagorean(mouseX, mouseY, width/3, height/3);
              float e = pythagorean(mouseX, mouseY, width/1.5, height/3);
    
    
              // click
    
              fill(eyecolour);
              ellipse(width/3, height/3, diameter, diameter);//draws left eye
              fill(random(255), random(255), random(255));//colour of pupils
              ellipse((width/2-180)+mouseX/9, (height/2-160)+mouseY/8, 20, 20);
              fill(eyecolour);//colour of eyes
              ellipse(width/1.5, height/3, diameter, diameter);//draws right eye
              fill(random(255), random(255), random(255));//colour of pupil 
              ellipse((width/2+80)+mouseX/9, (height/2-149)+mouseY/8, 20, 20);//pupil inside right eye
    
              if (d<diameter/2 || e<diameter/2) {
                eyecolour=color(237, 255, 3);//closes eyes if mouse is inside eyes
                fill(eyecolour);
                ellipse(width/3, height/3, diameter, diameter);
                ellipse(width/1.5, height/3, diameter, diameter);
                line(168, 280, 365, 280);//line inside left eye when mouse hovers over
                line(435, 280, 630, 280);//line inside right eye when mouse hovers over
                song3.play();
              } else {
                eyecolour=color(255);//keep colour as white
              }
            }
    
            float pythagorean (float mx, float my, float cx, float cy) {
              float dx = (mx-cx);
              float dy = (my-cy);
              float d = sqrt( pow(dx, 2)+pow(dy, 2) );
    
              return d;
            }
    
  • Answer ✓

    great

Sign In or Register to comment.