import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; Minim minim; AudioPlayer jingle; FFT fft; curverDrawer myDrawer; boolean showPoints = false; boolean fillShape = false; short timer = 0; //----------------------------------------- class curverDrawer { byte arms,links,state,myFill; float theta; float[] radius,radius2,c1rad,c2rad; float[] gRot, c1Rot, c2Rot; float[] gRotPos, c1RotPos, c2RotPos; float[] radiusRate,radiusVal,c1Rate,c1Val,c2Rate,c2Val; byte[] radiusMult,c1Mult,c2Mult; float[] qx1,qx2,qy1,qy2,qcx1,qcx2,qcy1,qcy2; short myHue,hueOff,myAlph; curverDrawer() { links = (byte)(random(5,9)); qx1 = new float[links]; qx2 = new float[links]; qy1 = new float[links]; qy2 = new float[links]; qcx1 = new float[links]; qcx2 = new float[links]; qcy1 = new float[links]; qcy2 = new float[links]; radiusRate = new float[links]; radiusVal = new float[links]; c1Rate = new float[links]; c2Rate = new float[links]; c1Val = new float[links]; c2Val = new float[links]; radiusMult = new byte[links]; c1Mult = new byte[links]; c2Mult = new byte[links]; radius = new float[links]; radius2 = new float[links]; c1rad = new float[links]; c2rad = new float[links]; gRot = new float[links]; c1Rot = new float[links]; c2Rot = new float[links]; gRotPos = new float[links]; c1RotPos = new float[links]; c2RotPos = new float[links]; arms = (byte)(random(5,9)); theta = TWO_PI/arms; for (byte i = 0; i < links; i++) { gRotPos[i] = 0; c1RotPos[i] = 0; c2RotPos[i] = 0; gRot[i] = random(-TWO_PI / (1440 * links),TWO_PI / (1440 * links)); c1Rot[i] = random(-TWO_PI / (1440 * links),TWO_PI / (1440 * links)); c2Rot[i] = random(-TWO_PI / (1440 * links),TWO_PI / (1440 * links)); radiusRate[i] = random(-TWO_PI / (1440 * links),TWO_PI / (1440 * links)); radiusVal[i] = 0; c1Rate[i] = random(-TWO_PI / (1440 * links),TWO_PI / (1440 * links)); c1Val[i] = 0; c2Rate[i] = random(-TWO_PI / (1440 * links),TWO_PI / (1440 * links)); c2Val[i] = 0; radiusMult[i] = (byte)(random(20*(1/links),100*(1/links))); c1Mult[i] = (byte)(random(30*(1/links),125*(1/links))); c2Mult[i] = (byte)(random(30*(1/links),125*(1/links))); radius[i] = random(50,300); c1rad[i] = random(50,300); c2rad[i] = random(50,300); } state = 0; myFill = 0; } void update() { fft.forward(jingle.mix); if (state == 0) { if (myFill == 125) { state = 1; myFill = 126; println("check"); } else { myFill++; } } else if (state == 2) { if (myFill <= 0) { state = 3; timer = 0; } else { myFill--; } } for (short i = 1; i < (512/6); i *=6) { for(byte q = 0; q < links; q++) { radiusVal[q] += (fft.getBand(i)/3000); c1Val[q] += fft.getBand(i+1)/1800; c2Val[q] += fft.getBand(i+2)/1800; if (gRot[q] > 0) { gRotPos[q] += fft.getBand(i+3)/3000; } else { gRotPos[q] -= fft.getBand(i+3)/3000; } if (c1Rot[q] > 0) { c1RotPos[q] += fft.getBand(i+4)/3000; } else { c1RotPos[q] -= fft.getBand(i+4)/3000; } if (c2Rot[q] > 0) { c2RotPos[q] += fft.getBand(i+5)/3000; } else { c2RotPos[q] -= fft.getBand(i+5)/3000; } } } for (byte i = 0; i < arms; i++) { for (byte k = 0; k < links; k++) { qx1[k] = (width/2) + ((radius[k] + (radiusMult[k] * sin(radiusVal[k]))) * cos((theta * i) + gRotPos[k])); qy1[k] = (height/2) + ((radius[k] + (radiusMult[k] * sin(radiusVal[k]))) * sin((theta * i) + gRotPos[k])); if (k == (links - 1)) { qx2[k] = (width/2) + ((radius[0] + (radiusMult[0] * sin(radiusVal[0]))) * cos((theta * (i+1))+ gRotPos[0])); qy2[k] = (height/2) + ((radius[0] + (radiusMult[0] * sin(radiusVal[0]))) * sin((theta * (i+1))+ gRotPos[0])); } else { qx2[k] = (width/2) + ((radius[k+1] + (radiusMult[k+1] * sin(radiusVal[k+1]))) * cos((theta * (i))+ gRotPos[k+1])); qy2[k] = (height/2) + ((radius[k+1] + (radiusMult[k+1] * sin(radiusVal[k+1]))) * sin((theta * (i))+ gRotPos[k+1])); } qcx1[k] = (width/2) + ((c1rad[k] + (c1Mult[k] * sin(c1Val[k]))) * cos((theta * i) + c1RotPos[k])); qcy1[k] = (height/2) + ((c1rad[k] + (c1Mult[k] * sin(c1Val[k]))) * sin((theta * i) + c1RotPos[k])); qcx2[k] = (width/2) + ((c2rad[k] + (c2Mult[k] * sin(c2Val[k]))) * cos((theta * i) + c2RotPos[k])); qcy2[k] = (height/2) + ((c2rad[k] + (c2Mult[k] * sin(c2Val[k]))) * sin((theta * i) + c2RotPos[k])); } /* if (showPoints) { stroke(126,myFill/2); if (fillShape) { fill(myHue,125,125,myFill/2); ellipse(qx1,qy1,10,10); fill(myHue,125,125,myFill/10); ellipse(qx2,qy2,15,15); fill(myHue,125,125,myFill/5); ellipse(qcx1,qcy1,10,10); fill(myHue,125,125,myFill/5); ellipse(qcx2,qcy2,15,15); } else { fill(125,myFill/2); ellipse(qx1,qy1,10,10); fill(64,myFill/10); ellipse(qx2,qy2,15,15); fill(10,myFill/5); ellipse(qcx1,qcy1,10,10); fill(10,myFill/5); ellipse(qcx2,qcy2,15,15); } } */ // stroke(126,myFill); for (byte l = 0; l < links; l++) { // stroke((126/links) * l,(126/links) * l,126); myHue = (short)(((126/arms/links)*i*l) + hueOff); if (myHue > 126) { myHue -= 126; } //myBrt = (short)(fft.getBand(((fft.specSize()/arms/links)*i*l)) * 25); // stroke(myHue,126,126,myFill); myAlph = (short)((fft.calcAvg(40,450))*5); strokeWeight((fft.calcAvg(40,450))/8); stroke(myHue,myAlph,126,25); bezier(qx1[l],qy1[l],qcx1[l],qcy1[l],qcx2[l],qcy2[l],qx2[l],qy2[l]); gRotPos[l] += gRot[l]; c1RotPos[l] += c1Rot[l]; c2RotPos[l] += c2Rot[l]; radiusVal[l] += radiusRate[l]; if (radiusVal[l] > TWO_PI) { radiusVal[l] = 0; } c1Val[l] += c1Rate[l]; if (c1Val[l] > TWO_PI) { c1Val[l] = 0; } c2Val[l] += c2Rate[l]; if (c2Val[l] > TWO_PI) { c2Val[l] = 0; } } } if (hueOff >= 126) { hueOff -= 126; } else { hueOff++; } } } //----------------------------------------- void setup() { size(700,700); //size(screen.width,screen.height); minim = new Minim(this); jingle = minim.loadFile("http://www.devinsmithmusic.com/vis/mp3s/history.mp3", 2048); // jingle.loop(); jingle.play(); fft = new FFT(jingle.bufferSize(), jingle.sampleRate()); colorMode(HSB,126); noFill(); smooth(); background(40); // background(64); myDrawer = new curverDrawer(); } //----------------------------------------- void draw() { // background(40); myDrawer.update(); if (timer == 1000) { myDrawer.state = 2; } if (myDrawer.state == 3) { myDrawer = new curverDrawer(); } timer++; /* if (jingle.isPlaying() == false) { jingle.play(); } */ } //----------------------------------------- void mouseClicked() { println("X: " + mouseX + " ||| Y: " + mouseY); if (fillShape) { fillShape = false; } else { fillShape = true; } }