allow microphone in your browser and the library options.
A fork of Shape changing w/sound by Joshua
xxxxxxxxxx
var mic;
function setup() {
createCanvas(800, 800);
mic = new p5.AudioIn();
mic.start();
}
function draw() {
background(255);
var vol = mic.getLevel(); // Valor entre 0 y 1
// Número de lados basado en el volumen
var numLados = round(map(vol, 0, 1, 3, 50));
// Dibujar el polígono
var radius = 100;
beginShape();
for (let i = 0; i < numLados; i++) {
let angle = TWO_PI / numLados * i;
let x = cos(angle) * radius;
let y = sin(angle) * radius;
vertex(x + width / 2, y + height / 2);
}
endShape(CLOSE);
console.log(vol);
}