xxxxxxxxxx
53
/**
* Audio: 'Mushrooms' by Komiku
* Public Domain.
* http://freemusicarchive.org/music/Komiku/Captain_Glouglous_Incredible_Week_Soundtrack/bibliothque
*/
let song;
let pulseSize = 0;
let fft;
function preload(){
song = loadSound('assets/Komiku_-_03_-_Mushrooms.mp3');
}
function setup() {
createCanvas(400, 400);
song.processPeaks(peaksProcessed);
// song.play();
fft = new p5.FFT();
}
function draw() {
background(0);
noStroke();
fill(random(255), random(255), 0);
pulseSize = max(pulseSize - 20, 0);
ellipse(width / 2, height / 2, pulseSize);
stroke(255, 50);
noFill();
let spectrum = fft.analyze();
for (let i = 0; i < spectrum.length; i++){
let d = map(spectrum[i], 0, 255, 0, height);
ellipse(width / 2, height / 2, d);
}
}
function peaksProcessed(peaks){
for (let i = 0; i < peaks.length; i++){
song.addCue(peaks[i], createPulse);
}
song.play();
}
function createPulse(){
pulseSize = 250;
}