xxxxxxxxxx
64
let webCam; // Declare variable to hold laptop camera capture
let webMic; // Declare variable to hold laptop audio capture
let feedbackButton; // Declare variable to hold last toggleMic button state
let feedback = true;
function setup() {
createCanvas(640, 360);
//
webCam = createCapture();
webCam.size(640, 360);
webCam.hide();
pixelDensity(1);
noStroke();
fill(0);
// Assign a new P5.AudioIn() object to variable webMic
webMic = new p5.AudioIn();
// Start with the mic off
webMic.start();
// Create a button to toggle the laptop mic off and on
feedbackButton = createButton('Gimmie Some Feedback!');
// button.position(20, 20);
feedbackButton.mousePressed(toggleMicInput);
}
function draw() {
background(200);
print(feedback);
webCam.loadPixels();
let stepSize = round(map(webMic.getLevel(), 0, 0.5, 8, 256));
for (let y = 0; y < webCam.height; y += stepSize) {
for (let x = 0; x < webCam.width; x += stepSize) {
let i = y * webCam.width + x;
let darkness = (255 - webCam.pixels[i * 4]) / 255;
let radius = stepSize * darkness;
// print(darkness);
ellipse(x, y, radius);
}
}
}
// A function to start and stop sound input from the mic
function toggleMicInput() {
if (feedback == false) {
webMic.stop();
feedbackButton.html('Gimmie Some Feedback!');
} else {
webMic.start();
feedbackButton.html('Stop The Madness!');
}
// feedback = !feedback;
}