xxxxxxxxxx
//The volume is a global variable
var volume = 0;
//The variable that contains my sound file
var sample;
//used to tune the responsiveness
// in theory the volume is between 0 and 1.0 but in practice the peak is often less
var maximumVolume = 0.3;
//Excerpt from Cathy Berberian's Stripsody (1966)
//Performed by Jerilyn Chou
function preload() {
sample = loadSound('120737__jakobthiesen__drum.mp3');
}
function setup() {
createCanvas(800, 800);
amp = new p5.Amplitude();
sample.loop();
}
function draw() {
//the background has to be redrawn every time
background("#F2E6D8");
// Get the overall volume of the sound clip
var v = amp.getLevel();
//Smooth the volume variable with an easing function
volume += (v - volume) / 3;
createCanvas(400, 400);
background("#FFD0EF");
fill(217, 97, 164);
noStroke();
ellipse(200,200,200,200);
fill("#FFF0C1");
beginShape();
vertex(50- volume*40,100);
vertex(100,180 + volume *70);
vertex(140,120);
endShape();
fill("#FFF0C1");
beginShape();
vertex(300,180);
vertex(250,110);
vertex(340-volume*100,120-volume*200);
endShape();
fill("#FFF0C1");
var rectWidth = map(volume, 0, maximumVolume, 10, 300);
rect(120,180,150,120, 40)
fill("#E199C3");
beginShape();
vertex(330 - volume*70,120);
vertex(300- volume*40,180);
vertex(280,140);
endShape();
fill("#E199C3")
rect(140,220,40,40,12)
fill("#E199C3")
rect(210,220,40,40,12)
fill("#E199C3")
rect(160,250,80,50,20)
fill("#603913")
rectMode(CENTER)
rect(160,235,20 +volume *20,20,5+volume*40)
rectMode(CORNER)
fill("#603913")
rect(215,227,20 + volume *20,20 +volume *20,2 +volume*40)
fill("#603913")
beginShape();
vertex(190+ volume*30,265);
vertex(210 - volume*30,265);
vertex(200,280);
endShape();
ellipse(10, 10, volume *100, volume *100)
}