// *****************************************??
// "BIO*LUMINESCENCE" by John Park
//  Written January 2009
// University of Oregon
// *****************************************//

// BallCount  =>  Change value for more or fewer balls
int bCount = 1200;

//The [] symbols denote arrays.  Do some research 
float [] yspd = new float[bCount];
float [] xspd = new float[bCount];
float [] xpos = new float[bCount];
float [] ypos = new float[bCount];
float [] bSize = new float[bCount];
float [] color1 = new float[bCount];
float gravity = 1.003;

// Below values get initialized (though they may change later in draw() function)
void setup(){
  size(1100,600);
  background(0);
  frameRate(25);
  smooth();
  //Initialize values
  // the FOR LOOP goes through all the items in each array
  for(int i=0; i<bCount; i++){
    xpos[i] = random(0,width);
    ypos[i] = random(0,height);
    yspd[i] = random(-2,4);
    xspd[i] = random(-4,4);
    // To change range of ball size, adjust below values
    bSize[i] = random(5,45);
    color1[i] = random(12,175);
  }
}

//The Constant redraw
void draw(){
 
  //The below section is for the fade...constant redraw of rectangle across screen
  fill(0,10);
  rectMode(CORNER);
  rect(0,0,width,height);
  
  //IMPORTANT for loop.  this is where ball position, gravity and other things take place
  for(int i=0; i<bCount; i++){
    ypos[i] -= (yspd[i]+random(-3,3));
    xpos[i] -= (xspd[i]+random(-3,3));
    ypos[i] *= gravity;
    
    
    if(ypos[i] < 0){
      ypos[i] = height + 10;
      xpos[i] = random(0,width);
      color1[i] = random(70,240);
    }
    
    // THE BELOW COMMENTED OUT section is an experiment in mosue detection.  Try it out if you want.
    /*
    if(abs(xpos[i]-mouseX)<92 && abs(ypos[i]-mouseY)<92){
      
      if((xpos[i]-mouseX)<0){
        xpos[i] -=((62-abs(xpos[i]-mouseX))/4) + random(0,70);
      }
      if((xpos[i]-mouseX)>0){
        xpos[i] +=((62-abs(xpos[i]-mouseX))/4)+ random(0,70);
      }
      if((ypos[i]-mouseY)>0){
        ypos[i] +=((62-abs(ypos[i]-mouseY))/4)+ random(0,70);
      }
      if((ypos[i]-mouseY)<0){
        ypos[i] -=((62-abs(ypos[i]-mouseY))/4) + random(0,70);
      }
      
    }
    */
    
 
    
    // THIS final section is where each ellipse actually gets drawn!
    fill(22,7,color1[i],160);
    noStroke();
    smooth();
    ellipse(xpos[i],ypos[i],bSize[i],bSize[i]);
  }
}