2014-09-03 39 views
0

我对编码完全陌生,字面上只是把事情搞砸了,而且还在努力学习。翻转频率可视化 - Java - 正在处理

第一:

所以,我有一段代码,它可以帮助我从一个音轨可视化的频率。简而言之,我只是想知道如何从左到右和从右到左翻转可视化。在代码中,我试图翻转左上角和左下角。

第二:

此外,如果任何人知道像一路延伸可视化长度草图的边缘。

就在一般情况下,如果你能向我解释为什么和如何,无论解决方案可能在这里学习。非常感谢提前的帮助。

这是我想要翻转的代码位。

for(int i = 0; i < song.left.size() - 1; i++) 
{ 
    //TOP - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 

整个草图:

import ddf.minim.*; 
import ddf.minim.analysis.*; 

Minim minim; 
AudioPlayer song; 
FFT fft; 

void setup() 
{ 
    size(1024, 512, P3D); 

    minim = new Minim(this); 

    song = minim.loadFile("mysong.mp3", 1024); 
    song.play(); 

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

void draw() 
{ 
    background(0); 
    fft.forward(song.mix); 

    stroke(255); 
    strokeWeight(3); 
    for (int i = 0; i < fft.specSize(); i = i+10) // i+10 Controls a sequence of repeated 

    { 
    //TOP - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 

    //TOP - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 
    } 
} 

回答

1

注:所有代码UNTESTED

// this is drawing one line from center of screen 
// to (top of screen - frequency) 
// returned from a specific "slot"in fft via fft.getBand(i) 

line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

// note that fft.getBand(i) is multiplied by 4. this is your range, 
// increase that number and lines will be bigger 


// the next line does the same but towards the bottom of screen 
// note th '+' instead of '-'' 
// so if you want to keep them with the same range you gotta change here as well 
// better, make a range var.. 
line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 

你有一个循环,从FFT得到每一个波段,并绘制一条线为每一个(实际上是两个,一个上下一个)。频率可视化的顺序由您通过fft的顺序给出。现在你要从0到fft列表的长度。 去向后和抽签将翻转:

// from end to begin... 
for (int i = fft.specSize()-1 ; i > 0; i-=10) 

    { 
    //TOP - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 
    } 

或者哟可以使用scale(-1, 0)水平翻转屏幕......然后你就可以进一步控制转换与push/popMatrix()

HTH