xxxxxxxxxx
71
particles = [];
let mic;
let r;
function setup() {
createCanvas(windowWidth, windowHeight);
mic = new p5.AudioIn();
mic.start();
}
function draw() {
background(0);
for (let i = 0; i < 5; i++) {
let p = new Particle();
particles.push(p);
}
for (let i = particles.length - 1; i >= 0; i--) {
particles[i].update();
particles[i].show();
if (particles[i].finished()) {
particles.splice(i, 1);
}
}
//sound
let vol = mic.getLevel();
console.log(vol)
r=map(vol,0,0.5,1,100);
}
class Particle {
constructor() {
this.x = random(width/4, 3*width/4);
this.y = height;
this.vx = random(-1, 1);
this.vy = random(-5, -1);
this.alpha = 255;
this.d = 5*r;
}
finished() {
return this.alpha < 0;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.alpha -= 3;
// this.d -= random(0.05, 0.1);
this.d -= random(0.05*r, 0.1*r);
}
show() {
noStroke();
fill(random(200,230), random(50, 150), 10, this.alpha);
ellipse(this.x, this.y, this.d);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}