Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How would I make the sound play? It doesn't work!

$
0
0

Code:

import processing.sound.*; //import sound file from data folder
SoundFile file;

void setup() {
  size(800, 800);
}

void draw() {

  background(255);
  drawFace(790, 750, 600, 600, 100, 673, 200, 245);
  checkNose(120);
  checkMouseNose();
  checkMouseLeftEye();
  checkMouseRightEye();
  checkMouseMouth();
  checkEyes(250, 550, 200, 150);
}


void drawFace(int circSize, int circXSize, int mouthY, int mouthXSize, int mouthYSize, int tongueY, int tongueXSize, int tongueYSize) {
  noFill();
  ellipse(width/2, height/2, circXSize, circSize);

  if (checkMouseMouth()) {
    fill(0);
    ellipse(width/2, mouthY, mouthXSize, mouthYSize - 100);
  } else {
    noFill();
    ellipse(width/2, mouthY, mouthXSize, mouthYSize);
  }

  fill(231, 158, 169);
  ellipse(width/2, tongueY, tongueXSize, tongueYSize);
}

void checkEyes(int eyeX, int eyeX2, int eyeY, int eyeSize) {

  noFill();
  ellipse(eyeX, eyeY, eyeSize, eyeSize);
  ellipse(eyeX2, eyeY, eyeSize, eyeSize);

  ellipse(map(mouseX, 10, 500, 210, 260), map(mouseY, 0, 500, 160, 215), 40, 40);
  ellipse(map(mouseX, 0, 500, 210, 260), map(mouseY, 0, 500, 160, 215), 20, 20);
  ellipse(map(mouseX, 0, 500, 510, 560), map(mouseY, 0, 500, 160, 215), 40, 40);
  ellipse(map(mouseX, 0, 500, 510, 560), map(mouseY, 0, 500, 160, 215), 20, 20);

  if (checkMouseLeftEye()) {
    fill(255, 0, 255);
    ellipse(eyeX, eyeY, eyeSize, eyeSize);
  } else {
    noFill();
    ellipse(eyeX, eyeY, eyeSize, eyeSize);
  }

  if (checkMouseRightEye()) {
    fill(255, 0, 255);
    ellipse(eyeX2, eyeY, eyeSize, eyeSize);
  } else {
    noFill();
    ellipse(eyeX2, eyeY, eyeSize, eyeSize);
  }
}

void checkNose(int circSize) {

  if (checkMouseNose()) {
    fill(255, 0, 0);
    ellipse(width/2, height/2, circSize, circSize);
  } else {
    noFill();
    ellipse(width/2, height/2, circSize, circSize);
  }
}

boolean checkMouseNose() {

  if (mouseX < 460 && mouseX > 340 && mouseY < 460 && mouseY > 340 && mousePressed) {
    // Load a soundfile from the /data folder of the sketch and play it back
    file = new SoundFile(this, "horn.mp3");
    file.play();
    return true;
  }
  return false;
}

boolean checkMouseLeftEye() {

  if (mouseX < 325 && mouseX > 175 && mouseY < 325 && mouseY > 175 && mousePressed) {
    // Load a soundfile from the /data folder of the sketch and play it back
    file = new SoundFile(this, "ouch.mp3");
    file.play();
    return true;
  }
  return false;
}

boolean checkMouseRightEye() {

  if (mouseX < 625 && mouseX > 475 && mouseY < 325 && mouseY > 175 && mousePressed) {
    // Load a soundfile from the /data folder of the sketch and play it back
    file = new SoundFile(this, "ouch.mp3");
    file.play();
    return true;
  }
  return false;
}

boolean checkMouseMouth() {

  if (mouseX < 700 && mouseX > 100 && mouseY < 650 && mouseY > 550 && mousePressed) {
    // Load a soundfile from the /data folder of the sketch and play it back
    file = new SoundFile(this, "mouth.mp3");
    file.play();
    return true;
  }
  return false;
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles