submission by jtoy
var fft,mic;
function randomSample(samples) {
  var sample = Math.random();
  
  return samples.find(
    element => (sample -= element.chance) < 0
  ).value;
}
function setup(){
  var myCanvas = createCanvas(windowWidth,windowHeight); //you must keep this line unmodified
 rects = []
 bins = 64
  colors = [255,200,100,70 ]
  var samples = [
  {
    value: 5,
    chance: .75
  }, {
    value: 10,
    chance: .2
  }, {
    value: 20,
    chance: .04
  }, {
    value: 90,
    chance: .01
  }
];
  for(i=0;i<1500;i++){
    rects.push({x:random(width),y:random(height),s:randomSample(samples) , spx:random(-5,5) ,spy:random(-2,2),c:random(colors),shape:random(['ellipse','rect']),bin:Math.floor(random(bins))  })
  }
  start= millis()
  position= 0

  fft = new p5.FFT(0,bins);
  mic = new p5.AudioIn();
  mic.start();
  fft.setInput(mic);


}
function fill_color(position,c){
  if(position == 0){
    fill(c,0,0)
  }else if (position == 1){
    fill(0,c,0)
  }else if (position == 2){
    fill(c,0,c)
  }else{
    fill(0,0,c)
  }
}

function draw() {
  //start writing your code here
  noStroke()
  background(0)
  spectrum = fft.analyze(bins)
  for(i=0;i<rects.length;i++){
     r = rects[i]
     x = r.x
     y=r.y
     s=r.s
     spx = r.spx
     spy = r.spy
     c = r.c
     bin = r.bin
     shape= r.shape
    fill_color(position,c)
    if(start+5000 < millis()){
      start=millis()
      position= ((position+1)%4)
    }
    plus_size = map(spectrum[bin],0,255,0,s*2)
    //if(shape == 'rect'){
     rect(x,y,s+plus_size,s+plus_size)  
   //}else if(shape =='ellipse'){
//     ellipse(x,y,s,s)  
 //  }
     if(random(1) >0.999){
       x+= random(-2,2)
       y+= random(-2,2)
     }
      x+= spx
      y+= spy
     if(x> width*1.5 && spx>0){
       x=-r.s
     }
     if(x< 0 && spx<0){
       x=width+r.s
     }
     if(y< 0 && spy<0){
       y=height+r.s
     }

    rects[i] = {x:x,y:y,s:s,spx:spx,spy:spy,c:c,shape:shape,bin:bin}
   }

}