Last active
August 29, 2015 14:13
-
-
Save micromeeeter/9c6b85c86bb79792bbe4 to your computer and use it in GitHub Desktop.
myVisualizer_03_likeVJ
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
//http://micromeeeter.hateblo.jp/entry/2015/01/11/222630 | |
//instoll controlP5 | |
//insert music file in data | |
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
Minim minim; | |
import controlP5.*; | |
ControlP5 cp5; | |
//for background | |
int H = 0; | |
int S = 0; | |
int B = 0; | |
int Ba; | |
//for Audio | |
AudioPlayer player; | |
FFT fft; | |
//for changing pattern | |
int pattern; | |
final int mode = 3; | |
int a; | |
//for pattern 0 | |
final int N = 3; | |
final int particle = 1000; | |
float[] r = new float[N]; | |
float[] R = new float[N]; | |
float[] period = new float[N]; | |
//for pattern 2 | |
final int M = 8; | |
float[] n = new float[M]; | |
float[] m = new float[M]; | |
float[] xs = new float[M]; | |
float[] ys = new float[M]; | |
float[] ellipseR = new float[M]; | |
void setup(){ | |
size(displayWidth, displayHeight); | |
frameRate(30); | |
colorMode(HSB, 360, 100, 100); | |
stroke(255); | |
minim = new Minim(this); | |
player = minim.loadFile("", 1024); //write the music file name bitween "" | |
fft = new FFT(player.bufferSize(), player.sampleRate()); | |
cp5(); | |
a = 0; | |
//pattern 0 | |
for(int i = 0; i < N; i++){ | |
float a = random(2, 18); | |
r[i] = (width / N / 2) / a * random(1, a); //inside circle | |
R[i] = width / N / 2 - r[i] - width / 150; //outside circle | |
period[i] = particle / random(1, 8); | |
} | |
//pattern2 | |
for(int i = 0; i < M; i++){ | |
n[i] = 1; | |
m[i] = 1; | |
} | |
} | |
void draw(){ | |
fft.forward(player.mix); | |
Ba = int(fft.getBand(100) * B / 5 + 10); | |
if(pattern == 0){ | |
background(H, S, Ba); | |
stroke(255); | |
strokeWeight(3); | |
for(int i = 0; i < N; i++){ | |
for(int j = 0; j < particle; j++){ | |
point(r[i] * cos(PI / (particle / 2) * j) + (R[i] - R[i] * (sin(PI / (period[i]) * j * frameCount) + 1) / 2) * cos(PI / (particle / 2) * j) + width / N * i + width / N / 2, r[i] * sin(PI / (particle / 2) * j) + (R[i] - R[i] * (sin(PI / (period[i]) * j * frameCount) + 1) / 2) * sin(PI / (particle / 2) * j) + height / 2) ; | |
} | |
} | |
}else if(pattern == 1){ | |
background(H, S, Ba); | |
stroke(255); | |
strokeWeight(3); | |
for(int i = 0; i < width / 2; i++){ | |
point(cos(PI / (width / 4) * i) * width / 5 + width / 2, sin(PI / (width / 4) * i) * sin((PI * i * frameCount / 800)) * width / 5 + height / 2); | |
} | |
}else if(pattern == 2){ | |
noStroke(); | |
fill(H, S, Ba, 50); | |
rect(0, 0, width, height); | |
fill(0, 0, 99, 150); | |
for(int i = 0; i < M; i++){ | |
xs[i] = (noise(n[i]) * (width * 3 / 5)) - width * 3 / 5 / 2; | |
ys[i] = (noise(m[i]) * (width * 3 / 5)) - width * 3 / 5 / 2; | |
n[i] += 0.001 + 0.001 * i; | |
m[i] += 0.002 + 0.001 * i; | |
ellipseR[i] = fft.getBand((i + 1) * 50) * width / 300 + 10 * (i + 1); | |
ellipse(xs[i] + width / 2, ys[i] + height/ 2, ellipseR[i], ellipseR[i]); | |
} | |
} | |
} | |
void cp5(){ | |
cp5 = new ControlP5(this); | |
cp5.addSlider("H") | |
.setPosition(10, 10) | |
.setSize(100, 10) | |
.setRange(0, 359) | |
.setColorTickMark(100); | |
cp5.addSlider("S") | |
.setPosition(10, 20) | |
.setSize(100, 10) | |
.setRange(0, 99); | |
cp5.addSlider("B") | |
.setPosition(10, 30) | |
.setSize(100, 10) | |
.setRange(0, 99); | |
cp5.addButton("PLAY") | |
.setPosition(150, 10) | |
.setSize(50, 10); | |
cp5.addButton("PAUSE") | |
.setPosition(150, 20) | |
.setSize(50, 10); | |
cp5.addButton("REWIND") | |
.setPosition(150, 30) | |
.setSize(50, 10); | |
} | |
void mousePressed(){ //set mode of pattern | |
a++; | |
pattern = a % mode; | |
} | |
void PLAY(){ | |
player.play(); | |
} | |
void PAUSE(){ | |
player.pause(); | |
} | |
void REWIND(){ | |
player.rewind(); | |
} | |
void stop(){ | |
player.close(); | |
minim.stop(); | |
super.stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment