setup()
setup() runs once when the sketch starts. It is the ideal place to initialize the canvas, set drawing modes, and call any setup functions you need.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
seed = random(10000);
generate();
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, making the artwork responsive to screen size
colorMode(HSB, 360, 100, 100, 100);- Switches from RGB to HSB (Hue, Saturation, Brightness) color mode with ranges 0-360 for hue, 0-100 for saturation, 0-100 for brightness, and 0-100 for alpha. HSB is more intuitive for generating harmonious color schemes
seed = random(10000);- Generates a random seed number between 0 and 10000 and stores it. This seed will be used to freeze the random number generator so the same seed always produces the same artwork
generate();- Calls the generate() function to draw the first generative artwork using the seed