Created
January 9, 2017 07:58
-
-
Save sys1yagi/cf08db6549f0c64c26c60f785b38e801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for processing program. | |
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.effects.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.spi.*; | |
import ddf.minim.ugens.*; | |
import com.jogamp.opengl.GL; | |
import com.jogamp.opengl.GL2ES2; | |
Minim minim; | |
AudioPlayer player; | |
PImage img; | |
FFT fft; | |
int specSize; | |
float volume; | |
int BUFSIZE = 512; | |
GL2ES2 gl; | |
float[] posX = new float[BUFSIZE]; | |
float[] posY = new float[BUFSIZE]; | |
float[] speedX = new float[BUFSIZE]; | |
float[] speedY = new float[BUFSIZE]; | |
float[] angle = new float[BUFSIZE]; | |
float stiffness = 0.6; | |
float damping = 0.9; | |
float mass = 6.0; | |
void setup(){ | |
size(854, 480, OPENGL); | |
minim = new Minim(this); | |
player = minim.loadFile("04.mp3",BUFSIZE); // path to music file. | |
fft = new FFT(player.bufferSize(), player.sampleRate()); | |
fft.window(FFT.HAMMING); | |
colorMode(HSB, 360, 100, 100, 100); | |
noStroke(); | |
player.play(); | |
frameRate(14); | |
PGraphicsOpenGL pg = (PGraphicsOpenGL)g; | |
PGL pgl = beginPGL(); | |
gl = ((PJOGL)pgl).gl.getGL2ES2(); | |
gl.setSwapInterval(1); | |
endPGL(); | |
for (int i = 0; i < BUFSIZE; i++) { | |
posX[i] = 0; | |
posY[i] = 0; | |
speedX[i] = 0; | |
speedY[i] = 0; | |
angle[i] = radians(random(0, 360)); | |
} | |
background(0); | |
} | |
void drawEllipse(int xOffset){ | |
specSize = fft.specSize(); | |
for(int i = 0; i < specSize; i++){ | |
float h = map(i, 0, specSize, 0, 180); | |
float ellipseSize = map(fft.getBand(i), 0, BUFSIZE/16, 0, width); | |
float x = map(i, 0, specSize, width/2, xOffset); | |
float w = width/float(specSize)/2; | |
fill(h, 80,80,7); | |
ellipse(x, height/2, ellipseSize, ellipseSize); | |
} | |
} | |
void drawGLSpring(){ | |
background(0); | |
backgroundFade(); | |
gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE); | |
translate(width/2, height/2); | |
fft.forward(player.mix); | |
float specSize = fft.specSize(); | |
float getBand; | |
for (int i = 0; i < specSize; i++){ | |
getBand = fft.getBand(i); | |
float addFroce = getBand* i * width/float(BUFSIZE)/2.0; | |
float direction = radians(random(0, 360)); | |
float addX = cos(direction) * addFroce; | |
float addY = sin(direction) * addFroce; | |
float forceX = stiffness * -posX[i] + addX; | |
float accelerationX = forceX / mass; | |
speedX[i] = damping * (speedX[i] + accelerationX); | |
float forceY = stiffness * -posY[i] + addY; | |
float accelerationY = forceY / mass; | |
speedY[i] = damping * (speedY[i] + accelerationY); | |
posX[i] += speedX[i]; | |
posY[i] += speedY[i]; | |
fill(255, 20); | |
float h = map(i, 0, specSize, 0, 360); | |
float r = getBand * i / 4.0 + 30.0; | |
fill(h, 100, 100, 10); | |
ellipse(posX[i], posY[i], r, r); | |
} | |
} | |
void draw() | |
{ | |
drawGLSpring(); | |
} | |
void stop(){ | |
player.close(); | |
minim.stop(); | |
super.stop(); | |
} | |
void backgroundFade() { | |
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); | |
gl.glBlendEquation(GL.GL_FUNC_ADD); | |
noStroke(); | |
fill(0, 5); | |
rect(0, 0, width, height); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment