Skip to content

Instantly share code, notes, and snippets.

@micromeeeter
Last active August 29, 2015 14:09
Show Gist options
  • Save micromeeeter/942839bde23d8a9da528 to your computer and use it in GitHub Desktop.
Save micromeeeter/942839bde23d8a9da528 to your computer and use it in GitHub Desktop.
myVisualizer_01
//http://instagram.com/p/u3SA8fx8pl/?modal=true
//insert music file in data
//import liblary
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
FFT fft;
final int N = 16; //Number of points
PVector[] point = new PVector[N];
float[] dist = new float[N]; //each radius
int[] turnValue = new int[N];
int[] strokeWeightPoint = new int[N];
void setup(){
size(600, 512);
frameRate(60);
colorMode(HSB, 360, 100, 100);
//load music file
minim = new Minim(this);
player = minim.loadFile("", 512); //insert file name between " "
fft = new FFT(player.bufferSize(), player.sampleRate());
smooth();
//set each values with random
for(int i = 0; i < N; i++){
point[i] = new PVector(random(-width / 2, width / 2), random(height));
dist[i] = random(1);
turnValue[i] = int(random(100, 600));
strokeWeightPoint[i] = int(random(2, 6));
}
}
void draw(){
//background
noStroke();
fill(223, 64, 99);
rect(0, 0, width, height);
translate(width / 2, 0);
drawFFT();
drawWave();
drawFilter();
drawPoint();
}
void stop(){
minim.stop();
player.close();
super.stop();
}
void keyPressed(){
//if you push 'a', the music will be started.
if(key == 'a'){
player.loop();
}
}
void drawFFT(){
noFill();
stroke(360, 0, 100);
strokeWeight(1);
int specSize = fft.specSize();
fft.forward(player.right);
for(int i = 0; i < specSize; i++){
float xR = map(i, 0, specSize, 0, height);
line(0, xR, fft.getBand(i) * 2, xR);
}
fft.forward(player.left);
for(int i = 0; i < specSize; i++){
float xL = map(i, 0, specSize, 0, height);
line(0, xL, -fft.getBand(i) * 2, xL);
}
}
void drawWave(){
fill(360, 0, 100, 50);
noStroke();
fft.forward(player.mix);
rect(- width / 2, 0, width, fft.getBand(250) * height / 2);
rect(- width / 2, height, width, - fft.getBand(300) * height / 2);
}
void drawFilter(){
noStroke();
fill(360, 0, 100, fft.getBand(200) * 150);
rect(- width / 2, 0, width, height);
}
void drawPoint(){
stroke(360, 0, 100);
for(int i = 0; i < N; i++){
//position of points
point[i].x += dist[i] * cos(PI / turnValue[i] * frameCount);
point[i].y += dist[(i + 2) % N] * sin(PI / turnValue[(i + 1) % N] * frameCount);
strokeWeight(fft.getBand(i * 20 + 100) * 15 + strokeWeightPoint[i]);
point(point[i].x, point[i].y);
}
for(int i = 0; i < (N / 4); i ++){
for(int j = 0; j < (N / 5); j++){
if(j == i){
continue;
}
strokeWeight(0.4);
line(point[i].x, point[i].y, point[j].x, point[j].y);
}
}
for(int i = (N / 4); i < (N / 2); i++){
for(int j = (N / 5); j < (N / 2); j++){
if(j == i){
continue;
}
line(point[i].x, point[i].y, point[j].x, point[j].y);
}
}
for(int i = (N / 2); i < (N * 3 / 4) ; i++){
for(int j = (N / 2); j < (N * 3 / 4); j++){
if(j == i){
continue;
}
line(point[i].x, point[i].y, point[j].x, point[j].y);
}
}
for(int i = (N * 3 / 4); i < N; i++){
for(int j = (N * 3 / 4); j < N; j++){
if(j == i){
continue;
}
line(point[i].x, point[i].y, point[j].x, point[j].y);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment