xxxxxxxxxx
// MONITOR MICROPHONE INPUT & VISUALIZE
// Define global variables
// To make variables accessible from every function in the sketch
var micLev;
var micGain;
function setup() {
createCanvas(800, 800);
background("#141432");
// Set additional gain for input data
// Change this value to increase or
// decrease the mic sensibility
micGain = 3;
// Initialize microphone
mic = new p5.AudioIn();
// Enable microphone
mic.start();
}
function draw() {
// set background color
background("#141432" + "10");
// assign micLev to microphone input volume
micLev = mic.getLevel() * micGain;
var x = width / 2;
var y = height / 2;
// Size of the pattern
var size = 300 + micLev * 500;
// Stroke color and weight of the triangles
stroke("#FFC896");
strokeWeight(2 + micLev * 5);
noFill();
for (var i = 0; i < 10; i++) {
push();
translate(x, y);
rotate(frameCount * 0.02 + i);
triangle(0, -size / 2 + i, -size / 2 + i, size / 2 - i, size / 2 - i, size / 2 - i);
pop();
}
}