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

Hi there! could someone please fix my code? Im sure its very simple. comment out the audio for now

$
0
0

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.5diameter/2 && mousePressed) { c=color(random(255), random(255), random(255)); song.play(); //boing sound when you click on the nose } else if (g<0.5diameter/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.5diameter, 0.5diameter);//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; }


Viewing all articles
Browse latest Browse all 2896

Trending Articles