import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import ddf.minim.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class finalMinim extends PApplet {




Minim minim;
AudioPlayer song;

     //position for expanding circle
      int circleX = PApplet.parseInt(random(500,540));   //define the circleX=int random between 425&475
      int circleY = PApplet.parseInt(random(100));       //define the circleY=int random between 0&100

  //size for expanding circle
  int circleSize=0;      //define the circleSize=0

      //count and count2
      int count=0;         //define the count=0    
      int count2=0;      //define the count2=0 


int rMax= PApplet.parseInt(random(80, 90));    //define the int rMax to be random between 90&100
int gMax= PApplet.parseInt(random(105, 120));    //define the int gMax to be random between 60&90
int bMax= PApplet.parseInt(random(109, 125));  //define the int bMax to be random between 100&110
int aMax= PApplet.parseInt(random(80, 90));    //define the int aMax to be random between 80&90
int r = PApplet.parseInt(random(rMax));      //define the int r=rMax
int g = PApplet.parseInt(random(gMax));       //define the int g=gMax
int b = PApplet.parseInt(random(bMax));         //define the int b=bMax
int a = PApplet.parseInt(random(aMax));         //define the int a=aMax

int c= color(r,g,b,a);
 public void drawEllipses(int c){    //define function drawEllipses
        int r = PApplet.parseInt(random(rMax));      //define the int r=rMax
        int g = PApplet.parseInt(random(gMax));       //define the int g=gMax
        int b = PApplet.parseInt(random(bMax));         //define the int b=bMax
        int a = PApplet.parseInt(random(aMax));         //define the int a=aMax

  //position and size for drawElipses
    float myX=  random(width);     //define the myX=int random between 0&width
    float myY=  random(height);    //define the myY=int random between 0&height
    float myW= random(width/6);       //define the myW=int random between 0&width/6
    float myH= random(height/6);      //define the myH=int random between 0&height/6
  

                 stroke(180); 
  fill(r, g, b, a);      //when drawEllipse is called fill with color r,g,b,a
  ellipse( myX, myY, myW, myH);
} 

public void expandCir(){      //define function expandCir
                    if (count>435){ 
                      
                         fill(200,200,200,20);  //when drawCir is called it gets filled with values r,g,b,a in parenthesis
                          ellipse(circleX,circleY,circleSize,circleSize); //draw ellipses with values inside parenthesis
                          circleSize=circleSize+4;            // circleSize increases by four - this is how fast it grows

                          if (circleSize>(height*3)){
                            circleSize=0;// if circleSize is greater than height*5 then circleSize=0
                            
}}
            if (count>1700){ 
                     stroke(130,30);  
                     fill(200,200,200,20);  //when drawCir is called it gets filled with values r,g,b,a in parenthesis
                      ellipse(circleX,circleY,circleSize,circleSize); //draw ellipses with values inside parenthesis
                         ellipse(circleX,600,circleSize,circleSize);  //draw ellipses with values inside parenthesis- position is defined here
                             circleSize=circleSize+4;            // circleSize increases by four - this is how fast it grows
                stroke(130,30);
                       if(circleSize>(height*4)){// if circleSize is greater than height*5 then 
                        circleSize=0;            //circleSize=0

}}}

public void setup(){    //call setup
          background(220);//gray background
          size(1040,700);//size of canvas
          stroke(180);  //stroke color
          smooth();    //smooth edges
          frameRate(40);//animation speed

minim = new Minim(this);

// this loads mysong.wav from the data folder
song = minim.loadFile("3_Libras.mp3");
song.play();
}

public void draw(){
  count=count+1; //count increases for monitoring timing
               count2=count2+1; //count increases to monitor timing as sequence repeats
              println(count);
                println(count2);
                if (count2==8455){
                  noLoop();}
               expandCir();    //call expandCir
    if (count>130) {
    drawEllipses(color(96, 0, bMax, a));//call draw Ellipses
  }          
 if (count<600) {
    drawEllipses(color(96, 0, bMax, a));//call draw Ellipses
  }
    if (count>=680) { // if count larger than 650
      drawEllipses(color(90, gMax, 0, a));//call draw Ellipses
    }

      if (count>900) { // if count larger than 650
        drawEllipses(color(100, g, bMax, aMax));//call draw Ellipses
      }
        if (count>1100) { 
          drawEllipses(color (rMax, 90, bMax, a));      //when drawEllipse is called fill with color r,g,b,a
        }
            if (count>2100) { 
            drawEllipses(color(r, g, 110, aMax));
            }
            if (count==2600) {
              count=0;
            
            }
          }


public void stop()
{
song.close();
minim.stop();

super.stop();
}
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "--full-screen", "--bgcolor=#666666", "--stop-color=#cccccc", "finalMinim" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
