import processing.serial.*; Serial port; import ddf.minim.*; Minim minim; AudioInput in; float[] x = new float[75]; float[] y = new float[75]; float[] angle = new float[75]; float[] speed = new float[75]; float[] radius = new float[75]; float speedRan = 1; float radRan = 150; float circleColor = 255; void setup(){ println(Serial.list()); // Open the port that the Arduino board is connected to (in this case #0) // Make sure to open the port at the same speed Arduino is using (9600bps) port = new Serial(this, Serial.list()[2], 9600); minim = new Minim(this); minim.debugOn(); // get a line in from Minim, default bit depth is 16 in = minim.getLineIn(Minim.MONO, 75); size(500, 500); smooth(); background(114, 168, 255); for(int i = 0; i < x.length; i++) { //set angles angle[i] = random(-0.1, 0.1); //set start positions x[i] = random(500); y[i] = random(500); //set radius radius[i] = random(150); //set speed speed[i] = random(0.5); } } void draw(){ background(114, 168, 255); for (int i = 0; i < x.length; i++) { //change angle angle[i] += random(-0.1, 0.1); //change x x[i] += cos(angle[i]) * speed[i]; //change y y[i] += sin(angle[i]) * speed[i]; //draw circles fill(255); stroke(140); strokeWeight(5); ellipse (x[i], y[i], radius[i], radius[i]); } for (int i = 0; i < x.length; i++) { float circleSound = in.left.get(i); if (circleSound > 0.02) { port.write('A'); } if (circleSound > .07) { port.write('B'); } if (circleSound > .12) { port.write('C'); } if (circleSound > .17) { port.write('D'); } port.write('L'); } for (int i = 0; i < x.length; i++) { //draw top circles circleColor = in.left.get(i); circleColor = map(circleColor, 0, 1, 0, 255); circleColor = -1 * (circleColor-255); fill(circleColor); noStroke(); ellipse (x[i], y[i], radius[i], radius[i]); } //recenter object after leaving stage and change size/speed for (int i = 0; i < x.length; i++) { if (x[i] < -150 || y[i] < -150){ x[i] = 250; y[i] = 250; speed[i] = random(speedRan); //speedRan +=.05; radius[i] = random(radRan); //radRan -= 0.1; } else if (x[i] > 650 || y[i] > 650){ x[i] = 250; y[i] = 250; speed[i] = random(speedRan); //speedRan +=.1; radius[i] = random(radRan); //radRan -= 0.1; } } } void stop() { // always close Minim audio classes when you are done with them in.close(); minim.stop(); super.stop(); }