import processing.opengl.*; import oscP5.*; import netP5.*; import ddf.minim.*; import ddf.minim.signals.*; OscP5 oscP5; NetAddress myRemoteLocation; Minim minim; AudioOutput out; SineWave sine; SineWave sine2; SineWave sine3; SineWave sine4; SineWave sine5; PImage img; int cellsize = 10; int columns, rows; float xrot = 0; float zrot = 0; float z = 1; color c = 0; float xrotOsc = 0; float zrotOsc = 0; float orientation = 0; float dampSpeed = 200; float touchX = 1; float touchY = 1; float touchX2 = 1; float touchY2 = 1; float freq, freq2, freq3, freq4, freq5; float pan; boolean accel = false; boolean explodingImage = true; boolean accelTweak = false; void setup() { size(1280,720, OPENGL); img = loadImage("abstract.jpg"); // Load the image columns = img.width / cellsize; // Calculate # of columns rows = img.height / cellsize; // Calculate # of rows oscP5 = new OscP5(this,12000); myRemoteLocation = new NetAddress("127.0.0.1",12001); minim = new Minim(this); out = minim.getLineOut(Minim.STEREO); sine = new SineWave(110, 0.2, out.sampleRate()); sine2 = new SineWave(220, 0.2, out.sampleRate()); sine3 = new SineWave(330, 0.2, out.sampleRate()); sine4 = new SineWave(440, 0.2, out.sampleRate()); sine5 = new SineWave(550, 0.2, out.sampleRate()); sine.portamento(1000); sine2.portamento(300); sine3.portamento(400); sine4.portamento(200); sine5.portamento(500); out.addSignal(sine); out.addSignal(sine2); out.addSignal(sine3); out.addSignal(sine4); out.addSignal(sine5); smooth(); } void draw() { if (accel == false) { if (touchX2 < 0.5) { camera((touchX2 - 0.5) * width * 2, (touchY2 - 0.5) * height * 2, 600, 0, 0, 0, 0.0, 1.0, 0.0); } else if (touchX2 > 0.5) { camera((touchX2 - 0.5) * width * 2, (touchY2 - 0.5) * height * 2, 600, 0, 0, 0, 0.0, 1.0, 0.0); } } else { camera(0, 0, 600, 0, 0, 0, 0.0, 1.0, 0.0); } background(0); // pixel for loops for ( int i = 0; i < columns; i++) { // Begin loop for rows for ( int j = 0; j < rows; j++) { int x = i*cellsize + cellsize/2; // x position int y = j*cellsize + cellsize/2; // y position int loc = x + y*img.width; // Pixel array location c = img.pixels[loc]; // Grab the color // smoothing if (abs(xrotOsc - xrot) < 2) { } else if (xrotOsc > xrot) { xrot = xrot + ((xrotOsc - xrot) / dampSpeed); } else { xrot = xrot - ((xrot - xrotOsc) / dampSpeed); } if (abs(zrotOsc - zrot) < 2) { } else if (zrotOsc > zrot) { zrot = zrot + ((zrotOsc - zrot) / dampSpeed); } else { zrot = zrot - ((zrot - zrotOsc) / dampSpeed); } z = 1; fill(c, 210); // iphone position, flipped or not if (orientation < 0 && accel == true) { fill(c, 230); rotateX(radians(xrot)); rotateZ(radians(zrot)); z = (zrot / float(width)) * brightness(c); } else if (orientation > 0 && accel == true) { fill(c, 100); rotateX(radians(xrot*-1)); rotateZ(radians(zrot*-1)); z = (xrot / float(height)) * brightness(c); } if (accel == false && explodingImage == true) { z = ((touchX * 3000) / float(width)) * brightness(c); } pushMatrix(); stroke(0); translate(x - 400, y - 200, z); if (explodingImage == true && accel == false) { rotateX(radians(touchY*90)); rotateY(radians(touchY*90)); rotateZ(radians(touchY*90)); box(cellsize, cellsize, cellsize); freq = map(touchY, 0, height, 110 * touchX * 5, 10); freq2 = map(touchY, 0, height, 220 * touchX * 5, 20); freq3 = map(touchY, 0, height, 330 * touchX * 5, 30); freq4 = map(touchY, 0, height, 440 * touchX * 5, 40); freq5 = map(touchY, 0, height, 550 * touchX * 5, 50); pan = map(touchX * width, 0, width, -1, 1); } else if (explodingImage == false && accel == true) { box(cellsize * touchX2 * 10, cellsize * touchY2 * 10, cellsize); freq = map(zrotOsc, 0, 90, 110 - zrotOsc, xrot/2); freq2 = map(zrotOsc, 0, 90, 220 - zrotOsc, xrot/3); freq3 = map(zrotOsc, 0, 90, 330 - zrotOsc, xrot/4); freq4 = map(zrotOsc, 0, 90, 440 - zrotOsc, xrot/5); freq5 = map(zrotOsc, 0, 90, 550 - zrotOsc, xrot/6); pan = map(xrotOsc * 10, 0, 90, -1, 1); } sine.setFreq(freq); sine2.setFreq(freq2); sine3.setFreq(freq3); sine4.setFreq(freq4); sine5.setFreq(freq5); sine.setPan(pan); sine2.setPan(pan); sine3.setPan(pan); sine4.setPan(pan); sine5.setPan(pan); popMatrix(); } } } void oscEvent(OscMessage theOscMessage) { //println(theOscMessage); if(theOscMessage.checkAddrPattern("/accxyz")==true) { explodingImage = false; accel = true; xrotOsc = (theOscMessage.get(0).floatValue()*90); //println("xrotOsc: " + xrotOsc); zrotOsc = (theOscMessage.get(1).floatValue()*90)*-1; //println("zrotOsc: " + zrotOsc); orientation = theOscMessage.get(2).floatValue(); } else { accel = false; } // Multitouch awesomeness :) if(theOscMessage.checkAddrPattern("/3/xy1")==true) { explodingImage = true; touchX = theOscMessage.get(0).floatValue(); //println("x: " + touchX); touchY = theOscMessage.get(1).floatValue(); //println("y: " + touchY); } if (theOscMessage.checkAddrPattern("/3/xy2")==true) { accelTweak = true; touchX2 = theOscMessage.get(0).floatValue(); //println("x2: " + touchX); touchY2 = theOscMessage.get(1).floatValue(); //println("y2: " + touchY); } else { accelTweak = false; } } void stop() { out.close(); minim.stop(); super.stop(); }