xxxxxxxxxx
var kick, amp1;//drumkick
var snare, amp2;//drumsnare
var hh, amp3;//drumhh
var lvl1, size1;
var lvl2, size2;
var lvl3, size3;
function setup() {
createCanvas(windowWidth, windowHeight);
kit = loadSound("bassdrum.mp3", keyTyped);
snare = loadSound("snare.mp3", keyTyped);
hh = loadSound("highhat.mp3", keyTyped);
amp1 = new p5.Amplitude();
amp2 = new p5.Amplitude();
amp3 = new p5.Amplitude();
}
function draw(){
lvl1 = amp1.getLevel();
lvl2 = amp2.getLevel();
lvl3 = amp3.getLevel();
size1 = map(lvl1, 0, 1, 0, 200);
size2 = map(lvl2, 0, 1, 0, 200);
size3 = map(lvl3, 0, 1, 0, 200);
}
function keyTyped(){
if(key === 'a'){
kit.play();
fill(random(40,90), 0, 0);
rect(width/3, height/2.5, size1*4, size1*4);
}
else if(key === 's'){
snare.play();
fill(0, 0, random(40,90));
rect(width/2, height/1.5, size2*4, size2*4);
}
else if(key === 'd'){
hh.play();
fill(0, random(40,90), 0);
rect(width/4, height/4, size3*4, size3*4);
}
}