xxxxxxxxxx
45
let snd;
function preload(){
sound = loadSound("assets/d0c444c005706a3eb2b8368119bc49d3.mp3");
}
function setup(){
createCanvas(400, 400);
fill(0);
noStroke();
// create a new Amplitude analyzer
analyzer = new p5.Amplitude();
// Patch the input to an volume analyzer
analyzer.setInput(sound);
}
function draw(){
background("darksalmon");
// Get the average (root mean square) amplitude
let rms = analyzer.getLevel();
fill(255, 255, 255, 0);
strokeWeight(random(1, 4));
stroke("white");
// Draw an ellipse with size based on volume
for (let i = 1; i <= 50; i += 1) {
ellipseX = i * random(0, 200)
ellipse(ellipseX, height / 2, 10 + rms * 200, 10 + rms * 200);
}
}
function mousePressed(){
if (sound.isPlaying()){
sound.pause();
} else {
sound.play();
background("pink");
}
}