import ddf.minim.*;
//declaration of minim object
Minim minim;
//audio input variable
AudioInput sound;
ArrayList <PVector> trace = new ArrayList <PVector>();
ArrayList <PVector> RGB = new ArrayList <PVector>();
FloatList soundlist = new FloatList();
void setup(){
size(800,800);
int xpos = mouseX;
int ypos = mouseY;
trace.add(new PVector(xpos,ypos,0));
soundlist.append(1);
minim = new Minim(this);
sound = minim.getLineIn(Minim.STEREO, 1024);
float startR = random(255);
float startG = random(255);
float startB = random(255);
RGB.add(new PVector(startR,startG,startB));
}
void draw(){
background(0);
//get the average sound_sample
float average_sound = 0;
for(int i = 0; i < sound.mix.size(); i++){
average_sound = average_sound + abs(sound.mix.get(i));
}
average_sound = average_sound/sound.mix.size();
average_sound = average_sound * 1250 + 50;
soundlist.append(average_sound);
PVector NewC = RGB.get(RGB.size()-1);
float startR = NewC.x + random(-15,15);
float startG = NewC.y + random(-15,15);
float startB = NewC.z + random(-15,15);
RGB.add(new PVector(startR,startG,startB));
int xpos = mouseX;
int ypos = mouseY;
trace.add(new PVector(xpos,ypos,0));
noStroke();
for(int i = 2; i < trace.size(); i++){
PVector newpos = trace.get(i);
PVector newC = RGB.get(i);
float radius = soundlist.get(i);
fill(newC.x,newC.y,newC.z);
ellipse(newpos.x,newpos.y,radius,radius);
}
}