import pitaru.sonia_v2_9.*; int MAX = 10; //MAX holds the number of instances of circles //declare array of Circles so that the code doesnt have to be written 10 times Circle[] myCircles = new Circle[MAX]; //square brackets declares the array and MAX defines the length of the array //declare _height and _width as an integer variable so they can be used later int _height; int _width; void setup() { //background(0); size(400,400); //start the live input sonia engine brum brum Sonia.start(this); LiveInput.start(); //set colorMode colorMode(RGB,255,255,255,100); } void draw() { //comment out background for slightly different effect //background(0); //fill array of circles using "New" -- all circles are random color, random x and y location //for loop, first value is 0, assign to variable i. so i starts at the first position //in the array which is 0 and iterates (runs through) them in sequence //fill the instance in the array with some random values //the for loop is placed in the void draw loop so that new random circles are draw every loop. //if the for loop was in void setup loop the same circles would be randomly moved around for (int i = 0; i < MAX; i++) { color tempcolor = color(0,random(255),0,random(100)); myCircles[i] = new Circle(tempcolor,random(width),random(height),int (_width + random(_width)), int (_height +random(_height))); } //declare meterData to be an int then liveInput.getLevel multiply by 1000 to //gain numbers that are in the range of pixel values within the Applet size int meterData = int(LiveInput.getLevel()*1000); println(meterData); //for every circle in the myCicles array, call the paint functions //call the for loop again because the last one in void setup ended with the curly brackets //if statement tells the paint function to paint only if the meter level is above 20. for (int i = 0; i < MAX; i++) { myCircles[i].paint(); //this if statement says if the meter data is above 20 then the width and height of the circles shall be equal to the meterData //meaning that the louder the liveInput the bigger the circles. if (meterData > 0){ _height = meterData; _width = meterData; } } } //define the class circle class Circle { color paintColour; float xpos; float ypos; int _width; int _height; //construct the circles with the constructor defining values and naming them Circle(color _paintColour, float xp, float yp, int w, int h) { paintColour = _paintColour; xpos = xp; ypos = yp; _width = w; _height = h; } //and paint them random x and y pos with the size defined by the input level void paint() { ellipseMode(CENTER); fill(paintColour); noStroke(); ellipse(random(width),random(height),_width + random(_width),_height + random(_height)); } } //stop the sonia engine on quit. public void stop(){ Sonia.stop(); }