let angle = 0
let mic;
let fft;
function setup() {
createCanvas(400, 400);
mic = new p5.AudioIn(); //AUDIO SETTING
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
}
function draw() {
background(220);
petals();
noStroke();
fill(255);
ellipse(200, 200, 100, 100); // the center of flower
function petals() {
push()
translate(200, 200); // flower leaves
rotate(angle);
noStroke();
const colors = ['magenta','red', 'orange','#7fff00','#0f0','#0ff','blue','#bf49ff'];
let waveform = fft.waveform();
for (let i=0; i<8; i++) {
let y = 100 - waveform[i]*100; //i want those flower leaves to rotate responds to mic
let color = colors[i];
fill(color)
ellipse(100, 0, 200, 60)
rotate(radians(45));
angle = angle +0.003
}
pop()
}
}
//I want my leaves to rotate in response to the loudness of real-time sound input from the microphone. I think I should use pff but... it doesn't work. Please help me TT