import processing.video.*; import ddf.minim.*; import ddf.minim.signals.*; color trackR; color trackG; color trackB; // video capture Capture capture; boolean haveVideo = false; String errorMessage; Minim minim; AudioOutput out; SineWave sineR; SineWave sineG; SineWave sineB; void setup() { size(320, 240); frameRate(30); try { println("Available video devices:"); String devices[] = Capture.list(); println(devices); // we just pick the default one capture = new Capture(this, width, height, 30); haveVideo = true; } catch( java.lang.Throwable ex ) { // try to catch any sort of error from Capture and inform the user errorMessage = ex.toString(); println("Error accessing video camera."); println(errorMessage); } // Create MovieMaker object with size, filename, // compression codec and quality, framerate // mm = new MovieMaker(this, width, height, "videoAs.mov"); colorMode(RGB,255,255,255,100); trackR = color(255); // Start off tracking for white trackG = color(255); // Start off tracking for white trackB = color(255); // Start off tracking for white noFill(); smooth(); minim = new Minim(this); // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16 out = minim.getLineOut(Minim.STEREO); // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out sineR = new SineWave(440, 0.5, out.sampleRate()); sineG = new SineWave(440, 0.5, out.sampleRate()); sineB = new SineWave(440, 0.5, out.sampleRate()); // set the portamento speed on the oscillator to 200 milliseconds sineR.portamento(200); sineG.portamento(200); sineB.portamento(200); // add the oscillator to the line out out.addSignal(sineR); out.addSignal(sineG); out.addSignal(sineB); } void captureEvent(Capture capture) { capture.read(); } void draw() { loadPixels(); image(capture, 0, 0); // background(0, 255, 0); // Local variables to track the color float closestDiffR = 500.0f; int closestXR = 0; int closestYR = 0; // Begin loop to walk through every pixel for ( int xr = 0; xr < capture.width; xr++) { for ( int yr = 0; yr < capture.height; yr++) { int locR = xr + yr*capture.width; // What is current color color currentR = capture.pixels[locR]; float r1 = red(currentR); float r2 = red(trackR); // Using euclidean distance to compare colors float dR = dist(r1,r2,r1,r2,0,0); // If current color is more similar to tracked color than // closest color, save current location and current difference if (dR < closestDiffR) { closestDiffR = dR; closestXR = xr; closestYR = yr; ellipse(closestXR,closestYR,9,9); fill(r1,0,0,33); } } } float closestDiffG = 500.0f; int closestXG = 0; int closestYG = 0; // Begin loop to walk through every pixel for ( int xg = 0; xg < capture.width; xg++) { for ( int yg = 0; yg < capture.height; yg++) { int locG = xg + yg*capture.width; // What is current color color currentG = capture.pixels[locG]; float g1 = green(currentG); float g2 = green(trackG); // Using euclidean distance to compare colors float dG = dist(g1,g2,g1,g2,0,0); // If current color is more similar to tracked color than // closest color, save current location and current difference if (dG < closestDiffG) { closestDiffG = dG; closestXR = xg; closestYR = yg; ellipse(closestXG-4,closestYG+4,9,9); fill(0,g1,0,33); } } } float closestDiffB = 500.0f; int closestXB = 0; int closestYB = 0; // Begin loop to walk through every pixel for ( int xb = 0; xb < capture.width; xb++) { for ( int yb = 0; yb < capture.height; yb++) { int locB = xb + yb*capture.width; // What is current color color currentB = capture.pixels[locB]; float b1 = blue(currentB); float b2 = blue(trackB); // Using euclidean distance to compare colors float dB = dist(b1,b2,b1,b2,0,0); // If current color is more similar to tracked color than // closest color, save current location and current difference if (dB < closestDiffB) { closestDiffB = dB; closestXB = xb; closestYB = yb; ellipse(closestXB+4,closestYB+4,9,9); fill(0,0,b1,33); } } } } void mouseDragged() { // Save color where the mouse is clicked in trackColor variable int locR = mouseX + mouseY*capture.width; int locG = mouseX + mouseY*capture.width; int locB = mouseX + mouseY*capture.width; trackR = capture.pixels[locR]; sineR.setFreq(locR); trackG = capture.pixels[locG]; sineG.setFreq(locG); trackB = capture.pixels[locB]; sineB.setFreq(locB); // float pan = map(mouseX, 0, width, -1, 1); // sineR.setPan(pan); } void stop() { out.close(); minim.stop(); super.stop(); }