xxxxxxxxxx
58
let particles = [];
let mic, fft;
let angle = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB);
noStroke();
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
for (let i = 0; i < width; i += 20) {
for (let j = 0; j < height; j += 20) {
particles.push({
x: i,
y: j,
clr: color(random(178, 255), 100, 100),
xOff: random(1000),
yOff: random(2000),
angleOff: random(TWO_PI),
radius: random(50, 200), // Adjust the radius range
});
}
}
}
function draw() {
background(243, 78, 28, 0.01);
let spectrum = fft.analyze();
for (let i = 0; i < particles.length; i++) {
let p = particles[i];
let spectrumIndex = Math.floor(map(p.x, 0, width, 0, spectrum.length - 1));
let amplitude = spectrum[spectrumIndex];
// Adjust particle's position based on the frequency's amplitude
p.x = width / 2 + cos(p.angleOff) * p.radius;
p.y = height / 2 + sin(p.angleOff) * p.radius;
// Use Perlin noise to add spiral-like motion
p.angleOff += map(noise(p.xOff), 0, 1, -0.1, 0.1);
p.xOff += 0.01;
let hue = map(amplitude, 0, 255, 178, 255);
p.clr = color(hue, 100, 100);
fill(p.clr);
ellipse(p.x, p.y, 1);
}
angle += 0.01;
}