import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import processing.sound.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class kod2 extends PApplet {


ArrayList<Shapes> drawed;
int pos;
 
Amplitude amp;
AudioIn in;
float ampt;
PVector startingPoint;
public void setup() {
  
  startingPoint = new PVector (random(0,width), random(0,height));

  
  drawed = new ArrayList<Shapes>(20);
  pos = 0;
  int rc = color(random(255), random(255), random(255), random(34, 60));
  drawed.add(pos, (new Shapes(random(255), random(255), rc, 0)));
  noStroke();
  
  amp = new Amplitude(this);
  in = new AudioIn(this, 0);
  in.start();
  amp.input(in);
}

public void draw() {
   ampt = amp.analyze();

  fill(255, 34);
  rect(0, 0, width, height);
  background(217, 202, 117);
  for ( Shapes s : drawed) {
    s.display();
    s.squiggle();
  }
  if (ampt>0.010f) {
    pos++;
    int rc = color(random(0), random(255), random(255));
    float randomX = random(0, 30);
    float randomY = random(0, 30);
    
    startingPoint.x += randomX; 
    startingPoint.y += randomY;
    
    if(startingPoint.x > width) {
       startingPoint.x -= randomX*50;
    }
    else if (startingPoint.x<0) {
      startingPoint.x += randomX*50;
    }
    
    if(startingPoint.y > height) {
       startingPoint.y -= randomY*50;
    } 
    else if (startingPoint.y<0) {
      startingPoint.y += randomX*50;
    }
    
    drawed.add(pos, (new Shapes(startingPoint.x,  startingPoint.y, rc, ampt)));
  }
}



class Shapes {
  //float x=+ampt*230;
  //float y=+ampt*230;
  
  float x=10;
  float y=10;
  float size = 1;
  int c;
  // constructor
  Shapes(float xx, float yy, int cc, float iSize) {
    x = xx + random(-120,120);
    y = yy + random(-120,120);
    c = cc;
    size = iSize;
  }

  public void display() {
    fill(c);

    ellipse(x, y, 1+size*230,  1+size*230);
  }
  public void squiggle() {
    x += random(-5, 5);
    y += random(-5, 5);
  }
}
  public void settings() {  fullScreen(); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "kod2" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
