xxxxxxxxxx
34
function setup() {
createCanvas(400, 300);
capture = createCapture(VIDEO);
capture.size(400, 300);
capture.hide();
mic = new p5.AudioIn();
mic.start();
}
function draw() {
micLevel = mic.getLevel();
capture.loadPixels();
for (let i = 0; i < capture.pixels.length; i += 4) {
if (random() < 0.9) {
next_i = int(map(micLevel, 0, 1, 0, 30)) * 4; // some pixels more to the right, some less to the right. That's why mapping micLevel to a range of 0 to 30 pixels apart from the current pixel index
if (next_i < capture.pixels.length) {
capture.pixels[i + next_i] = capture.pixels[i];
capture.pixels[i + next_i + 1] = capture.pixels[i + 1];
capture.pixels[i + next_i + 2] = capture.pixels[i + 2];
}
}
}
capture.updatePixels();
tint("red")
image(capture, 0, 0, width, height);
}
function keyPressed() {
if (key == "s") {
saveGif("capture.gif", 5);
}
}