読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

円形のFFTビジュアライザ

f:id:aa_debdeb:20161012202946j:plain
/**
* circular fft visualizer
*
* @author aa_debdeb
* @date 2016/10/20
*/

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioInput in;
FFT fftL, fftR;

float radious = 80;
color c2 = color(255, 255, 100);
color c1 = color(127, 255, 212);

void setup(){
  size(640, 640);
  minim = new Minim(this);
  in = minim.getLineIn(Minim.STEREO, 1024);
  fftL = new FFT(in.bufferSize(), in.sampleRate());
  fftR = new FFT(in.bufferSize(), in.sampleRate());
}

void draw(){
  background(0);
  translate(width / 2, height / 2);
  fftL.forward(in.left);
  fftR.forward(in.right);
  stroke(lerpColor(c1, c2, map(in.mix.level(), 0, 0.03, 0, 1)));
  strokeWeight(1);
  for(int i = 0; i <= fftL.specSize() / 2; i += 2){
    float angle = HALF_PI - map(i, 0, fftL.specSize() / 2, 0, PI) ;
    float len = fftL.getBand(i) * 30;
    line(radious * cos(angle), radious * sin(angle), (radious + len) * cos(angle), (radious + len) * sin(angle));
  }
  for(int i = 0; i <= fftL.specSize() / 2; i += 2){
    float angle = HALF_PI + map(i, 0, fftL.specSize() / 2, 0, PI) ;
    float len = fftR.getBand(i) * 30;
    line(radious * cos(angle), radious * sin(angle), (radious + len) * cos(angle), (radious + len) * sin(angle));
  }
}