// applet size variables int xSize = 600; int ySize = 350; int xMid = xSize/2; int yMid = ySize/2; int frameRate = 30; int counter = 0; Camera camera; Sound sound; SpikeBall spikeBall; boolean micInput = true; void setup(){ size(xSize, ySize); //lights(); //smooth(); framerate(frameRate); ellipseMode(CENTER_RADIUS); colorMode(HSB,255); Sonia.start(this); // create camera (distance, lensAngle) camera = new Camera(37.0, 30.0); // create sound (sampleName, bands, history, speed, degrade) sound = new Sound("none", 512, 300, 10, 1.02); if (micInput){ LiveInput.start(sound.bands); LiveInput.useEqualizer(true); LiveInput.useEnvelope(true,1.5); } // create spikeBall (numSpikes, spikeLength) spikeBall = new SpikeBall(64, 256); for (int i=0; i<2; i++){ g.lightKind[i] = SPECULAR; } } void loop(){ background(175,100,35); doLights(); sound.exist(); camera.exist(); spikeBall.exist(); counter ++; delay(10); } void doLights(){ for (int i=0; i<2; i++){ g.lightX[i] = 0.5 * (i%2 - .5); g.lightY[i] = 0.25 * i; g.lightZ[i] = .5 + i; g.lightR[i] = 0.1; g.lightG[i] = i/3.0; g.lightB[i] = 0.0; } } class Spike{ int index; int spikeLength; float fillColor; float sineOffset, sine2Offset; float mySize; float r; float g; float b; float bb; float X, Y, Z, x, y, z; float waveOffset; Spike(int sentSpikeLength, int sentIndex){ spikeLength = sentSpikeLength; index = sentIndex; waveOffset = random(TWO_PI); } void undulate(){ beginShape(QUAD_STRIP); for(int i = 0; i <= sound.history - sound.speed; i += sound.speed){ sineOffset = (sin(i/100.0 - counter/6.0 + waveOffset) * 1.0); sine2Offset = (sin(i/100.0 - counter/10.0 + waveOffset) * 3.0); fillColor = abs(sound.spectrumHistory[i][index]); bb = abs(sound.spectrumHistory[i][index] * 2.0) - i/10.0 + sineOffset*50.0; fill(0 + (sq(X - x) * 2000.0),200,bb * 0.2); x = X; y = Y; z = Z; X = ((sound.history - i)/1000.0 + sound.spectrumHistory[i][index]/350.0) * (sound.history - i)/sound.history; if (index%4 > 0){ Y = (sound.spectrumHistory[i][index]/25.0 + sineOffset); } else { Y = (sound.signalHistory[i][index]/25.0 + sineOffset); } Z = (i)/sound.speed + sound.spectrumHistory[i][index]/1000.0; if (i < sound.speed * 20.0){ Y *= (i / (sound.speed * 20.0)); Z *= (i / (sound.speed * 20.0)); } noStroke(); if (i%(sound.speed * 2) > 0){ vertex(-X, Y, Z); fill(175 + (sq(X - x) * 2000.0),200,sq(X - x) * 255.0 + bb); vertex(X, Y, Z); } else { vertex(X, Y, Z); fill(175 + (sq(X - x) * 2000.0),200,bb * 0.2); vertex(-X, Y, Z); } } endShape(); } } class SpikeBall{ Spike[] spike; int numSpikes; int spikeLength; float bodyRadius; float xRot, yRot, zRot; SpikeBall(int sentNumSpikes, int sentSpikeLength){ numSpikes = sentNumSpikes; spikeLength = sentSpikeLength; spike = new Spike[numSpikes]; for (int i=0; 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/80.0) * 65.0)) * .2; yPos -= (yPos - (sin(counter/135.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, 200); translate(cos(counter/100.0) * 3.0, sin(counter/50.0) * 1.5, -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