xxxxxxxxxx
37
class Box {
constructor(x, y, h, note) {
this.x = x;
this.y = y;
this.h = h;
this.active = false;
this.env = new p5.Envelope();
this.env.setRange(1, 0);
this.env.setADSR(0.01, 0.1, 0.5, 0.01);
this.note = note;
this.osc = new p5.Oscillator();
this.osc.start();
this.osc.freq(midiToFreq(this.note));
this.osc.amp(this.env);
}
display() {
push();
translate(this.x, this.y);
if (this.active) {
stroke(this.h, 100, 80, 100);
fill(this.h, 100, 100, 50);
sphere(boxSize/2);
this.env.play();
} else {
stroke(this.h, 100, 50, 100);
fill(this.h, 100, 70, 50);
box(boxSize - boxSize/4);
}
pop();
}
}