setup()
setup() runs once when the sketch starts. Here it's used to configure the canvas, color system, and audio analyzer before any drawing happens.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 255);
angleMode(RADIANS);
// p5.FFT(smoothing, bins) – smoothing ~0.8 keeps motion smooth
fft = new p5.FFT(0.85, 1024);
initRings();
textFont('sans-serif');
textSize(13);
}
Line-by-line explanation (7 lines)
createCanvas(windowWidth, windowHeight);- Makes the canvas fill the entire browser window so the rings can be centered on any screen size.
colorMode(HSB, 360, 100, 100, 255);- Switches p5's color system from RGB to Hue-Saturation-Brightness, which makes it much easier to pick vivid neon colors by just changing a hue number (0-360).
angleMode(RADIANS);- Ensures any angle-based math (like sin/cos used in the breathing animation) uses radians, p5's default and JavaScript's native math unit.
fft = new p5.FFT(0.85, 1024);- Creates the FFT (Fast Fourier Transform) analyzer that will turn raw audio into frequency data. 0.85 is smoothing (higher = less jittery), 1024 is the resolution of the analysis.
initRings();- Calls the helper function that builds the three ring objects (bass, mid, treble) with their starting radii.
textFont('sans-serif');- Sets the font used for the HUD overlay text.
textSize(13);- Sets the default text size in pixels for all text drawn afterward.