setup()
setup() runs exactly once when the sketch starts. It's where you initialize your canvas, set modes, and establish starting positions for animated objects.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100);
noStroke();
planetX = width / 2;
planetY = height / 2;
}
Line-by-line explanation (5 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, so the animation adapts to any screen size.
colorMode(HSB, 360, 100, 100);- Switches from RGB to HSB color mode where Hue (0-360) controls rainbow color, Saturation (0-100) controls color intensity, and Brightness (0-100) controls lightness—this makes animating colors much easier.
noStroke();- Disables outlines around shapes so only the fill color is visible, creating cleaner solid polygons.
planetX = width / 2;- Positions the planet's center horizontally in the middle of the canvas.
planetY = height / 2;- Positions the planet's center vertically in the middle of the canvas.