//based on Explode for images by Daniel Shiffman import processing.video.*; import krister.Ess.*; AudioStream myStream; AudioInput myInput; boolean inputReady=false; float[] streamBuffer; FFT myFFT; float bufferSize; int steps; float limitDiff; int numAverages=32; float myDamp=.1f; float maxLimit,minLimit; int cellsize = 15; int cols, rows; Capture video; PFont word; float eyeX = 500.0; float eyeY = 508.0; //float eyeZ = 2400.0; float eyeZ = 1100.0; float varX = 500.0; float varY = 508.0; float varZ = 1100.0; float centX = 500.0; float centY = 350.0; float centZ = 10.0; float upX = 0.0; float upY = 1.0; float upZ = 0.0; float sval = 0.0; int bounce = 0; void setup(){ size(1024, 768, P3D); framerate(10); word = loadFont("Courier-24.vlw"); textFont(word, 24); //set up columns and rows cols = width/cellsize; rows = height/cellsize; colorMode(RGB,255,255,255,100); // use default capture device video = new Capture(this, 1024, 768, 12); camera(eyeX, eyeY, eyeZ, centX, centY, centZ, upX, upY, upZ); Ess.start(this); myInput = new AudioInput(512); myFFT = new FFT(1024); myFFT.equalizer(true); minLimit = .005; maxLimit = .05; myFFT.limits(minLimit,maxLimit); myFFT.damp(myDamp); myFFT.averages(numAverages); steps=1024/numAverages; limitDiff=maxLimit-minLimit; myStream = new AudioStream(myInput.size); streamBuffer = new float[myInput.size]; myStream.start(); myInput.start(); } void captureEvent(Capture cam){ cam.read(); } public void audioInputData(AudioInput theInput) { myFFT.getSpectrum(myInput); } void draw(){ // clear background background(150); if(bounce == 1){ sval -= 0.01; } else { sval += 0.01; } if(sval > 2) { sval = 2; bounce = 1; } if(sval < 1.0) { sval = 1.0; bounce = 0; } /* scale(sval); //rotateX(PI/9-sval+1.0); rotateY(PI*sval); rotateZ(PI*sval/9-0.125); translate(0, 0, -200); rotateY(PI/9); //rotateX(PI/6); */ // columns for ( int i = 0; i < cols;i++) { // rows for ( int j = 0; j < rows;j++) { int x = i*cellsize + cellsize/2; int y = j*cellsize + cellsize/2; int loc = (video.width - x - 1) + y*video.width; // mirror float r = video.pixels[loc] >> 16 & 0xFF;; float g = video.pixels[loc] >> 8 & 0xFF; float b = video.pixels[loc] & 0xFF; // make new color color c = color(r*3,g*1.5,b*.125,75); float threshold = 50 * (mouseX/ (float) width); float z = myFFT.spectrum[i]* threshold * brightness(c) - 100.0f; //varY = mouseY; //varZ = 700+mouseY-(tan(PI*60/360.0)); // camera(varX, varY, varZ, centX, centY, centZ, upX, upY, upZ); // Translate to the location, set fill and stroke, and draw the box pushMatrix(); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); box(cellsize,cellsize,(brightness(c))); popMatrix(); } } }