xxxxxxxxxx
48
var splash = [];
let objectsplash;
function setup() {
createCanvas(1200, 800);
frameRate(60);
mic = new p5.AudioIn();
mic.start();
}
function draw() {
background(0);
var vol = mic.getLevel();
// print(vol);
if (frameCount%1800 == 0) {
splash = [];
}
if (vol > 0.01 && frameCount%3 == 0) {
objectsplash = new Splash(random(50,1150), random(50,650), [random(255),random(255),random(255)], vol);
splash.push(objectsplash);
}
for (let i = 0; i < splash.length; i++) {
splash[i].pop();
}
}
class Splash {
constructor(x,y, color, vol){
this.x = x;
this.y = y;
this.r = 0;
this.color = color;
this.vol = vol;
this.opacity = 255;
}
pop() {
fill(this.color[0],this.color[1],this.color[2], this.opacity/2);
stroke(this.color[0],this.color[1],this.color[2], this.opacity);
circle(this.x, this.y, this.r);
this.r += (1 + this.vol*100);
this.opacity = this.opacity - 2;
}
}