Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

FFT Landscape generator

$
0
0

Hi there, I followed the Terrain Generator by Perlin Noise tutorial from youtube, and I tried to switch the perlin noise with an FFT of the mic audio input. X axis is fine, in the horizon I can clearly see my FFT effect, in the y axis I can't get the progressive generation, so to create a landscape from the sequences of FFT moments/frames. to get the Effect That the observer walks toward the horizon self-generated by FFT. Below is where I am:

//code
import processing.sound.*;

int cols, rows;
int scl = 20;
int w = 2000;
int h = 1600;
float [] [] terrain;
float flying = 0;
FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];


void setup () {
size (600, 600, P3D);
cols = w /scl;
rows = h /scl;
terrain = new float[cols][rows];


  // Create an Input stream which is routed into the Amplitude analyzer
  fft = new FFT(this, bands);
  in = new AudioIn(this, 0);

  // start the Audio Input
  in.start();

  // patch the AudioIn
  fft.input(in);

}


void draw() {

  fft.analyze(spectrum);

  flying -= 0.1;

float yoff = flying;
for  (int y = 0; y < rows; y++){
float xoff = 0;
  for (int x = 0; x < cols; x++){
    terrain[x] [y] = map(spectrum[x], 0, 1, 0, 10000);
    xoff += 0.2;
}
yoff += 0.2;
}



background(0);
  stroke(255);
  noFill();
  translate(width/2, height/2+50);
  rotateX(PI/3);
  translate(-w/2, -h/2);

for (int y = 0; y < rows-1; y++){
beginShape(TRIANGLE_STRIP);
for  (int x = 0; x < cols; x++) {
vertex(x*scl, y*scl , terrain[x][y]);
vertex(x*scl, (y+1)*scl , terrain[x][y+1]);
//rect(x*scl, y*scl, scl, scl);

}
endShape();
}

}

Could someone help me? Thanks a lot


Viewing all articles
Browse latest Browse all 2896

Trending Articles