xxxxxxxxxx
49
let scale, audio, fft, src_length, peaks, processed_peaks;
let detectors = [];
function preload() {
audio = loadSound("phased_abstractions.mp3");
}
function setup() {
createCanvas(640, 640);
src_length = audio.duration();
peaks = audio.getPeaks();
audio.processPeaks(function(new_peaks) {
processed_peaks = peaks;
});
fft = new p5.FFT();
colorMode(HSL);
noFill();
strokeWeight(3);
audio.loop();
background(0)
}
function draw() {
background(0, 100, 0, 0.2);
let spectrum = fft.analyze();
let bass = fft.getEnergy("bass");
let mid = fft.getEnergy("mid");
let treble = fft.getEnergy("treble");
scale = map(cos(frameCount / 100) * bass, -255, 255, 50, width / 2)
strokeWeight(map(bass, 200, 255, 3, 10))
translate(width / 2, height / 2);
rotate((frameCount/100) + radians(treble))
stroke(frameCount % 360, 50, 50)
beginShape();
for (let i=0; i<100; i+=5) {
let x = cos(i * sin(frameCount / 1000)) * scale;
let y = sin(i * cos(frameCount / 1000)) * scale;
curveVertex(x, y);
}
endShape();
}