帮基友做的作业里的一部分,写完以后她说用不到这个就发出来了()
大概就是监听了一下麦克风然后转角度,写的很傻
有参考openprocessing上的代码
对没错搜到的所有代码都是p5.js(……) java模式表示死亡xxx
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
FFT fft;
int h,m,s;
float[] fftReal;
void setup() {
//窗口大小
size(800, 600);
minim = new Minim(this);
in = minim.getLineIn();
//FFT(int timeSize, float sampleRate)
//通过一个timeSize大小并且采样速率为sampleRate的缓冲区构造FFT
fft = new FFT(in.bufferSize(), in.sampleRate());
}
void draw(){
background(0);
fft.forward(in.mix);
//时钟的部分
//显示时间
//textFont(createFont("Helvetica", 65));
textFont(createFont("lcdD", 65));
textAlign(CENTER);
fill(255);
h=hour();
m=minute();
s=second();
if(m<10 && s<10){text(h+":"+"0"+m+":"+"0"+s,width/2,height/2+100/3-3);}
else if(m<10 && s>=10){text(h+":"+"0"+m+":"+s,width/2,height/2+100/3-3);}
else if(m>=10 && s<10){text(h+":"+m+":"+"0"+s,width/2,height/2+100/3-3);}
else if(m>=10 && s>=10){text(h+":"+m+":"+s,width/2,height/2+100/3-3);}
textAlign(LEFT);
textFont(createFont("Helvetica", 11));
//显示圆形频谱
fftReal = fft.getSpectrumReal();
//fftImag = fft.getSpectrumImaginary();
float ang=0;
float angle=PI/40;
int circRad = 180;
int circThick = 5;
int maxSpectrum = 80;
for(int i = 0; i < maxSpectrum; i+=1) {
float dist = fftReal[i];
//float dist2 = fftReal[i+1];
stroke(fftReal[i], 125, 186);
//stroke(255, 236, 149);
strokeWeight(3);
line(width/2 - cos(ang)*(circRad+dist+circThick), height/2 + sin(ang)*(circRad+dist+circThick), width/2 - cos(ang)*(circRad-dist-circThick), height/2 + sin(ang)*(circRad-dist-circThick));
//line(width/2 - cos(ang)*(circRad+dist+circThick), height/2 + sin(ang)*(circRad+dist+circThick), width/2 - cos(ang+angle)*(circRad+dist2+circThick), height/2 + sin(ang+angle)*(circRad+dist2+circThick));
//line(width/2 - cos(ang)*(circRad-dist-circThick), height/2 + sin(ang)*(circRad-dist-circThick), width/2 - cos(ang+angle)*(circRad-dist2-circThick), height/2 + sin(ang+angle)*(circRad-dist2-circThick));
ang+=angle;
}
strokeWeight(1);
}
……并没有背景,因为懒直接截了作业的图(