xxxxxxxxxx
39
let mic;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(RGB);
mic = new p5.AudioIn();
mic.start();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw() {
background("black")
let vol = mic.getLevel();
push();
fill("lavender");
star(width / 2, height / 2, vol * 5000, vol * 2500, 12);
pop();
console.log(vol);
}
function star(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}