setup()
setup() runs exactly once when the sketch starts. It is the place to initialize your canvas, set colors and styles, and populate data structures. In this sketch, it prepares everything before draw() begins its infinite loop.
function setup() {
createCanvas(windowWidth, windowHeight);
// Use HSB color mode for easier transparency and color selection
// Hue: 0-360, Saturation: 0-100, Brightness: 0-100, Alpha: 0-1
colorMode(HSB, 360, 100, 100, 1);
noStroke(); // No outlines for the circles
initializeCircles(); // Create our initial set of circles
}
Line-by-line explanation (4 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a canvas that fills the entire browser window
colorMode(HSB, 360, 100, 100, 1);
Switches to HSB (hue, saturation, brightness) with alpha transparency, making colors and blending more intuitive
noStroke();
Removes outlines from shapes so circles appear smooth without borders
initializeCircles();
Populates the circles array with 15 new Circle objects
createCanvas(windowWidth, windowHeight);- Creates a p5.js canvas that matches the full width and height of the browser window, making the sketch responsive
colorMode(HSB, 360, 100, 100, 1);- Switches from the default RGB color mode to HSB, where hue ranges 0-360 (the color spectrum), saturation and brightness range 0-100, and alpha ranges 0-1 for transparency—this makes creating trendy color palettes much simpler
noStroke();- Tells p5.js not to draw outlines around shapes, so the circles will have clean, soft edges
initializeCircles();- Calls the custom initializeCircles() function to create and populate the circles array with 15 new Circle objects, each with random properties