aaajiao
YaBB Newbies
Offline
Posts: 35
Re: Sonia Samples
Reply #3 - Dec 10th , 2007, 1:32pm
import processing.core.*; import fullscreen.*; import pitaru.sonia_v2_9.*; import SoniaHelper.*; //import processing.opengl.*; /** * Mirror * by Daniel Shiffman. * * Each pixel from the video source is drawn as a rectangle with rotation based on brightness. */ import processing.video.*; FullScreen fs; float rad; int spectrumLength=256; // Needs to be power of 2 int bandsteps; float maxdist,damperval; SoniaHelper ffthelper; float pt[]; // Size of each cell in the grid int cellSize = 5; // Number of columns and rows in our system int cols, rows; // Variable for capture device Capture video; void setup() { size(640, 480, P3D); frameRate(30); cols = width / cellSize; rows = height / cellSize; rectMode(CENTER); Sonia.start(this); LiveInput.start(spectrumLength); // LiveInput.useEnvelope(true,1f); LiveInput.useEqualizer(true); // SoniaHelper(int _n, int _nbands,boolean doAvg) ffthelper=new SoniaHelper(spectrumLength,32,false); ffthelper.setMaxLimits(200,2000); damperval=0.1f; ffthelper.setDamper(damperval); pt=new float[spectrumLength*2]; for(int i=0; i<spectrumLength; i++) { pt[i*2]=random(width-50)+25; pt[i*2+1]=random(height-50)+25; } bandsteps=spectrumLength/ffthelper.band.length; maxdist=ffthelper.maxMaximum-ffthelper.maxMinimum; //colorMode(RGB, 255, 255, 255, 100); // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 12); fs = new FullScreen(this); // enter fullscreen mode fs.enter(); } void draw() { doSoundInput(); for(int i=0; i<spectrumLength; i++) { //fill(255,0,128, 255*ffthelper.spectrum[i]); // scale rad according to spectrum value, using // cubic interpolation to give organic values. rad=2+50*(ffthelper.spectrum[i]*ffthelper.spectrum[i]); } if (video.available()) { background(0); video.read(); video.loadPixels(); // Not bothering to clear background // Begin loop for columns for (int i = 0; i < cols; i++) { // Begin loop for rows for (int j = 0; j < rows; j++) { // Where are we, pixel-wise? int x = i*cellSize; int y = j*cellSize; int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image float r = red(video.pixels[loc]); float g = green(video.pixels[loc]); float b = blue(video.pixels[loc]); // Make a new color with an alpha component float av = r+g+b; //fill(55,random(0,255),random(34,255)); // Code for drawing a single rect // Using translate in order for rotation to work properly pushMatrix(); translate(x,y); rotate(av/32.0); rect(0+rad,0+rad,av/26.0,av/26.0); popMatrix(); } } } } public void doSoundInput() { LiveInput.getSpectrum(); ffthelper.update(LiveInput.spectrum); }