// applet size variables int xSize = 400; int ySize = 300; int xMid = xSize/2; int yMid = ySize/2; int frameRate = 30; int counter = 0; Camera camera; SampleReader sampleReader; SpikeBall spikeBall; boolean micInput = true; //float[] clearZ; //BImage myField, myRing; void setup(){ size(xSize, ySize); //lights(); //smooth(); framerate(frameRate); ellipseMode(CENTER_RADIUS); colorMode(HSB,255); background(0,0,0); Sonia.start(this); //init_blur(2); // create camera (distance, lensAngle) camera = new Camera(37.0, 30.0); // create sampleReader (sampleName, bands, history, speed, degrade) sampleReader = new SampleReader("none", 512, 500, 20, 1.0); if (micInput){ LiveInput.start(sampleReader.bands); LiveInput.useEqualizer(true); LiveInput.useEnvelope(true,1.5); } // create spikeBall (numSpikes, spikeLength) spikeBall = new SpikeBall(50, 128); /*myField = loadImage("field.gif"); brightToAlpha(myField); myRing = loadImage("field2.gif"); brightToAlpha(myRing);*/ //clearZ=new float[width*height]; //System.arraycopy(g.zbuffer,0,clearZ,0,clearZ.length); } void loop(){ background(175,180,89); //fill(51,0,0,50); //rect(0,0,xSize,ySize); //System.arraycopy(clearZ,0,g.zbuffer,0,clearZ.length); //fastblur(); sampleReader.exist(); camera.exist(); spikeBall.exist(); counter ++; //saveFrame("screenGrabs/test-####.tif"); delay(5); } class SpikeBall{ int numSpikes; int spikeLength; float bodyRadius; float fillColor, bb; float sineOffset, sine2Offset; float mySize; float x, y, z, x2, y2, z2; float xRot, yRot, zRot; float[] positionRandomizer; SpikeBall(int sentNumSpikes, int sentSpikeLength){ numSpikes = sentNumSpikes; spikeLength = sentSpikeLength; positionRandomizer = new float[numSpikes]; for (int i=0; i 0){ y = (sampleReader.spectrumHistory[i][j]/25.0 + sineOffset); } else { y = (sampleReader.signalHistory[i][j]/25.0 + sineOffset); } z = (i)/sampleReader.speed + sampleReader.spectrumHistory[i][j]/500.0; if (i < sampleReader.speed * 20.0){ y *= (i / (sampleReader.speed * 20.0)); z *= (i / (sampleReader.speed * 20.0)); } if (i%(sampleReader.speed * 2) > 0){ vertex(-x, y, z); stroke(50,255,bb,100); fill(180 - sampleReader.spectrumHistory[0][3] * 5.0 + 120, 150, 0); vertex(x, y, z); } else { vertex(x, y, z); fill(0 + fillColor/3.0, 225, bb); vertex(-x, y, z); } //stroke(fillColor * 3.5, fillColor * 0.5, 0.0); //if (i > 0){ // line(x,y,z,x2,y2,z2); // } } endShape(); pop(); } push(); translate(0,0,0); fill(0,0,0,150); stroke(0,255,0,15); sphere(1.5); stroke(175,150,35,100); noFill(); bodyRadius -= (bodyRadius - (sampleReader.signalHistory[0][2]/175.0 + 1.5)) * .1; sphere(bodyRadius); pop(); } } class SampleReader{ Sample mySample; int bands; int history; int speed; float degrade; float[] spectrum; float[] signal; float spectrumHistory[][]; float signalHistory[][]; float timeCounter = 0.0; float theCount = 0; int startFrame; SampleReader(String sentSampleName, int sentBands, int sentHistory, int sentSpeed, float sentDegrade){ bands = sentBands; history = sentHistory; speed = sentSpeed; degrade = sentDegrade; if (sentSampleName != "none"){ mySample = new Sample(sentSampleName); } spectrumHistory = new float[history][bands]; signalHistory = new float[history][bands]; } void exist(){ processMicSpectrum(); } void prepareClip(){ startFrame = int(timeCounter * 44100); spectrum = mySample.getSpectrum(bands, startFrame); mySample.play(startFrame, startFrame + (44100 / frameRate)); } void processMicSignal(){ LiveInput.getSpectrum(false); for(int i = history - speed; i >= speed; i -= speed){ for(int j = 0; j < bands; j ++){ signalHistory[i][j] -= (signalHistory[i][j] - (signalHistory[i-speed][j] * degrade)) * .5; } } for(int j = 0; j < bands; j ++){ signalHistory[0][j] -= (signalHistory[0][j] - (constrain(LiveInput.signal[j]*.25,0,100))) * .7; } } void processMicSpectrum(){ LiveInput.getSpectrum(false); for(int i = history - speed; i >= speed; i -= speed){ for(int j = 0; j < bands; j ++){ spectrumHistory[i][j] -= (spectrumHistory[i][j] - (spectrumHistory[i-speed][j] * degrade)) * .75; signalHistory[i][j] -= (signalHistory[i][j] - (signalHistory[i-speed][j] * degrade)) * .75; } } for(int j = 0; j < bands; j ++){ spectrumHistory[0][j] -= (spectrumHistory[0][j] - (constrain(LiveInput.spectrum[j]*.25,0,200))) * .7; signalHistory[0][j] -= (signalHistory[0][j] - (constrain(LiveInput.signal[j]*.25,0,200))) * .9; } } void setCounter(){ timeCounter += (1.0f/float(frameRate)); } } class Camera{ // camera variables float xPos, yPos; float rotationVar; float elevation; float azimuth; float twist; float distance; float lensAngle; boolean autoRotate = true; Camera (float sentDistance, float sentLensAngle){ distance = sentDistance; lensAngle = sentLensAngle; } void exist(){ findRotation(); setCamera(); } void findRotation(){ if (autoRotate){ xPos -= (xPos - (cos(counter/50.0) * 65.0)) * .2; yPos -= (yPos - (sin(counter/25.0) * 86.0)) * .2; azimuth = cos(counter/500.0); } else { xPos -= (xPos - (xMid - mouseX)) * .2; yPos -= (yPos - (yMid - mouseY)) * .2; } } void setCamera(){ beginCamera(); perspective(lensAngle, (float)xSize / (float)ySize, 1.0f, 500); translate(cos(counter/100.0) * 6.0, sin(counter/50.0) * 3.0, -distance); twist = radians(xPos); elevation = radians(yPos); rotateY(-twist); rotateX(elevation); rotateZ(-azimuth); endCamera(); } } int radius; int w, h, wm, hm, wh, div; int R[]; int G[]; int B[]; int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw; int vmin[]; int vmax[]; int dv[]; void init_blur(int rad) { radius = rad; w = width; h = height; wm = w-1; hm = h-1; wh = w*h; div = radius+radius+1; R = new int[wh]; G = new int[wh]; B = new int[wh]; vmin = new int[max(w,h)]; vmax = new int[max(w,h)]; dv = new int[256*div]; for (i=0;i<256*div;i++){ dv[i]=(i/div); } } void fastblur(){ yw=yi=0; for (y=0;y>16; gsum+=(p & 0x00ff00)>>8; bsum+= p & 0x0000ff; } for (x=0;x>16; gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8; bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff); yi++; } yw+=w; } for (x=0;x