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

Why does it work this way? Need help for a schoolproject

$
0
0

Hey Guys,

first of all, sorry if my englisch isnt perfect , because im from Germany but i will try my best :D

Im working on a school project and i need to create a Musicvisualizer in 3D. Now ive wrote a code thats works good and i also like how it looks, but i dont know why it work in this way. the Code is creating many Spheres if i use the translate command to place it in the middel of the screen. In my opinion it looks very cool with more of these Spheres but i dont understand why there are so many. If I just write the Sphere command without the Translate , it only creates one Sphere thats moving to the analysed float from the FFT.

Can someone maybe tell me why this happens ? because i need to present and also explain how my code works in front of my teacher. hope you can help me , thx and greetings.


CODE :

import shapes3d.*;
import shapes3d.animation.*;
import shapes3d.utils.*;

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



import peasy.*;
int i;
PeasyCam cam;
Minim minim;
AudioPlayer player;
FFT fft;
void setup() {
  size(800, 800, P3D);
  cam = new PeasyCam(this, 0, -100, 200, 1000);
  cam.setMinimumDistance(20);
  cam.setMaximumDistance(5000);

  minim= new Minim(this);
  player= minim.loadFile("bmth.mp3");
  player.play();

  fft = new FFT(player.bufferSize(), player.sampleRate());
}

void draw() {
  rotateX(-.5);
  rotateY(-.5);
  background(0);
  //fill(255,0,0);
  //sphere(i);
  keyPressed();

  fft.forward(player.mix);// used to analyze the frequency coming from the mix
  for (int i = 0; i < fft.specSize(); i += 50)// specSize is changing the range of analysis
  {
    noFill();

    ellipse(width/2, height/2, 500, fft.getFreq(i/2)*2.5);

    ellipse(width/2, height/2, 200+fft.getFreq(i/2)*2.5, 300+fft.getFreq(i/2)*2.5);

    ellipse(width/2, height/2, fft.getFreq(i/2)*2.5, 400);

    fill(255, 0, 0);

    stroke(255, 255, 255);

    pushMatrix();
    translate(400, 400, 5);

    sphereDetail(20, 3);

    sphere(50+ fft.getFreq(i/2)*0.2);

    popMatrix();

    sphereDetail(3, 20);

    translate(400, 50, 5);

    sphere(50+ fft.getFreq(i/2)*0.2);

    pushMatrix();

    translate(0, 750, 5);
    sphere(50+ fft.getFreq(i/2)*0.2);
    popMatrix();
  }
}

void keyPressed () {

  if ( key=='s') {
    player.pause();
  }
  if ( key=='d') {
    player.play();
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles