let input;
let bg;
function setup() {
createCanvas(800, 600);
input = new p5.AudioIn();
input.start();
bg = color(0, 255, 0);
background(bg);
}
function draw() {
let volume = input.getLevel();
let threshold = 0.02;
if (volume > threshold) {
drawCircleCluster(volume);
}
}
function drawCircleCluster(volume) {
noStroke();
let largerCircleColor = color(255, 165, 0);
fill(largerCircleColor);
let cx = random(width);
let cy = random(height);
let numCircles = int(random(5, 10));
for (let i = 0; i < numCircles; i++) {
let angle = random(TWO_PI);
let radius = random(10, 80);
let x = cx + cos(angle) * radius;
let y = cy + sin(angle) * radius;
let size = map(volume, 0, 1, 5, 150);
size = constrain(size, 5, 150);
circle(x, y, size);
}
}
function keyPressed() {
if (key === 'C' || key === 'c') {
background(bg);
}
}
To create my own sound based canvas I took inspiration from the kusama rooms and sound dot we created during the workshop. It should look like a splatter effect as you make louder sounds.
//Click on the iframe and click C to clear the dots
Code adapted from
Sojamo's sketch