xxxxxxxxxx
64
let mic;
let bubbles = [];
const MAX_BUBBLES = 1000;
function setup() {
createCanvas(600, 400);
// https://p5js.org/reference/#/p5.AudioIn
mic = new p5.AudioIn();
mic.start();
push();
//colorMode(HSB);
for(let i = 0; i < MAX_BUBBLES; i++){
const xRand = random(0, width);
const yRand = random(0, height);
const randDiameter = random(0, 100);
//const hue = map()
const fillColor = color(255, 128);
const bubble = new Bubble(xRand, yRand, randDiameter, fillColor);
bubbles.push(bubble);
}
pop();
}
function draw() {
background(128);
const xCircle = width / 2;
const yCircle = height /2;
const micLevel = mic.getLevel();
for(const bubble of bubbles){
bubble.micLevel = micLevel;
bubble.draw();
}
}
class Bubble{
constructor(x, y, diameter, fillColor){
this.x = x;
this.y = y;
this.maxDiameter = diameter;
this.fillColor = fillColor;
this.micLevel = 0;
}
draw(){
push();
fill(this.fillColor);
let diameter = this.micLevel * this.maxDiameter;
circle(this.x, this.y, diameter);
pop();
}
}