35 lines
732 B
JavaScript
35 lines
732 B
JavaScript
let audio = document.getElementById('audio');
|
|
let file_path = audio.src;
|
|
|
|
var sound;
|
|
var fft;
|
|
|
|
function preload() {
|
|
sound = loadSound(audio.src);
|
|
}
|
|
|
|
function setup() {
|
|
createCanvas(500, 500);
|
|
colorMode(HSB);
|
|
angleMode(DEGREES);
|
|
sound.play();
|
|
fft = new p5.FFT(0.9, 128);
|
|
}
|
|
|
|
function draw() {
|
|
background(0);
|
|
var spectrum = fft.analyze();
|
|
noStroke();
|
|
translate(width / 2, height / 2);
|
|
|
|
for (var i = 0; i < spectrum.length; i++) {
|
|
var angle = map(i, 0, spectrum.length, 0, 360);
|
|
var amp = spectrum[i];
|
|
var r = map(amp, 0, 256, 20, 100);
|
|
var x = r * cos(angle);
|
|
var y = r * sin(angle);
|
|
stroke(i, 255, 255);
|
|
line(0, 0, x, y);
|
|
}
|
|
}
|