xxxxxxxxxx
60
var mic;
let prevVol;
let currentVisualization = 0;
let VISUALIZATION_COUNT = 4;
let amp;
var fft;
function setup() {
createCanvas(800, 400);
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT(0.9, 32);// 128 spectrum.length
fft.setInput(mic);
background(0,50);
}
let x = 0;
function draw() {
drawFFT();
background(0, 20);
}
function drawFFT() {
var spectrum = fft.analyze();
console.log(spectrum.length);
noStroke();
//let redValue = map(amp, 0, 256, 0, 255);
// stroke(redValue,0 , 255 - redValue);
//line(x, height, x, height - y);
rainbow()
//ellipse(x,height - y,redValue)
}
function rainbow() { let offset=0
noFill()
r = noise(offset * 0.2) * 255;
g = noise(offset * 0.3) * 255;
b = noise(offset * 0.1) * 255;
stroke(r, g, b);
strokeWeight(20);
w = noise(offset * 0.1) * width;
h = noise(offset * 0.1) * height * 1.5;
offset = offset + 0.03;
for (let i = 0; i < spectrum.length; i++) {
let amp = spectrum[i];
let y = map(amp, 0, 256, 0, height);
let x = map(i, 0, spectrum.length, 0, width);
let redValue = map(i, 0, spectrum.length, 0, 255);
arc(width / 2, (height / 10) * 8, redValue, redValue, PI, 0);
}}