setup()
setup() runs once at sketch start. It configures the canvas, colors, and initial state. The noLoop() call is key — it makes the sketch event-driven rather than frame-driven, reducing CPU load.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
textFont('monospace');
textSize(13);
generateWeather();
noLoop(); // draw only when we explicitly ask for it
}
Line-by-line explanation (6 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a canvas that fills the entire browser window for an immersive radar display
colorMode(HSB, 360, 100, 100, 100);
Switches to Hue-Saturation-Brightness color space, making it natural to map storm intensity to color ramps
noLoop(); // draw only when we explicitly ask for it
Stops the draw loop from running automatically — saves CPU and waits for user interaction
createCanvas(windowWidth, windowHeight);- Creates a canvas sized to fill the entire browser window, giving the radar map a full-screen presence
colorMode(HSB, 360, 100, 100, 100);- Switches color space to HSB (Hue 0–360°, Saturation 0–100%, Brightness 0–100%, Alpha 0–100), which makes it easy to map weather intensity to hue gradients
textFont('monospace');- Sets text to a monospace font, mimicking the look of classic weather station displays
textSize(13);- Sizes all text labels at 13 pixels for readable radar annotations
generateWeather();- Builds the initial weather field, radar echoes, and tornado positions
noLoop();- Disables automatic looping — draw() only runs when redraw() is called after user interaction, saving CPU and battery