xxxxxxxxxx
69
////////////////////////////////////////////////////
//
// Computation in Design
//
////////////////////////////////////////////////////
let input;
let soundInputLevelBooster;
let threshold;
function setup() {
canvas = createCanvas(2000, 280, SVG); // 592x842 pixels = A4
background(255);
pixelDensity(1);
// change value to >1.0 to boost
// audio input level
soundInputLevelBooster = 2.0;
// If the volume > 0.1, a rect is drawn at a random location.
// The louder the volume, the larger the rectangle.
threshold = 0.1;
// Create an Audio input
input = new p5.AudioIn();
input.start();
}
// function mousePressed() {
// if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
// let fs = fullscreen();
// fullscreen(!fs);
// }
// }
// function windowResized() {
// resizeCanvas(windowWidth, windowHeight);
// }
function soundDrawing(volume) {
let s = volume * 700;
noFill();
stroke(100);
ellipse(frameCount, height/2, s);
}
function draw() {
let volume = input.getLevel();
if (volume > threshold) {
if (frameCount % 3 == 0) {
soundDrawing(volume);
}
}
}
function keyPressed() {
if(key === 's' || key === 'S') {
save("sound-circles-" + frameCount + ".png");
}
}