You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB
JavaScript

let mic, fft;
let spacer;
let t = 0; // time variable
function setup(){
createCanvas(710, 400);
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
noStroke();
fill(255);
}
function draw() {
background(0);
strokeWeight(2);
stroke(255);
//frameRate(10);
let spectrum = fft.analyze();
//console.log(spectrum.length);
// console.log(spectrum);
// beginShape();
// for (i = 0; i < spectrum.length; i++) {
// vertex(i, map(spectrum[i], 0, 255, height, 0));
// }
// endShape();
beginShape();
for (x = 0; x < spectrum.length; x= x+5) {
// stroke(255);
//noStroke();
let alpha = map(spectrum.length, 0,1024,0,100)
strokeWeight(2);
stroke(114,126,143, alpha);
noFill();
print(alpha)
//fill(255,255,255, alpha);
//console.log(spectrum[x]);
line(width/random(8) ,height/random(8) , spectrum[x]*10, spectrum[x]*8);
//line(random(300,700) ,random(200,300), spectrum[x]*10, spectrum[x]*15);
line(spectrum[x]*8, spectrum[x]*8, spectrum[x]*12, alpha*10);
//rect(600 , 100, spectrum[x]/1.8, spectrum[x]/1.8);
}
endShape();
}