xxxxxxxxxx
38
// Adapted from Paolo Pedercini.
//----------------------------------------------
//I have declared volume as a global variable
var volume = 0;
function setup() {
createCanvas(800, 800);
// Create an Audio input
mic = new p5.AudioIn();
// Start the Audio Input
mic.start();
}
//----------------------------------------------
function draw() {
// The background has to be redrawn every time
background("DodgerBlue");
// Get the overall volume (between 0 and 1.0)
var v = mic.getLevel();
// Smooth the volume variable with a running average
volume = 0.9 * volume + 0.1 * v;
//computers like radians but you can change that!
angleMode(DEGREES);
var mouth = map(volume, 0, 1, 0, 180);
fill("black");
stroke("black");
strokeWeight(3);
var eyeHeight = 200;
var eyeWidth = 200;
arc(width/2, height/2, eyeHeight, eyeWidth, 360 - mouth, 0 + mouth, PIE);
}