setup()
setup() runs once when the sketch starts. It initializes the canvas, sets up color mode for beautiful HSB colors, and populates the initial 20 seed points that will drift around and form the Voronoi diagram.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 1);
noStroke();
for (let i = 0; i < INITIAL_SEEDS; i++) {
seeds.push(createSeed(random(width), random(height)));
}
}
๐ง Subcomponents:
createCanvas(windowWidth, windowHeight)
Creates a canvas that fills the entire window
colorMode(HSB, 360, 100, 100, 1)
Sets color mode to HSB (Hue, Saturation, Brightness) for easier color control in the crystal effect
for (let i = 0; i < INITIAL_SEEDS; i++) { seeds.push(createSeed(random(width), random(height))); }
Creates 20 seed points at random positions that will become the centers of Voronoi cells
Line by Line:
createCanvas(windowWidth, windowHeight)- Creates a canvas that matches the full window dimensions, allowing the sketch to fill the entire screen
colorMode(HSB, 360, 100, 100, 1)- Switches to HSB color mode where hue ranges 0-360, saturation 0-100, brightness 0-100, and alpha 0-1. This makes it easier to create harmonious colors
noStroke()- Disables stroke outlines by default, though strokes are added later in drawCellEdges()
for (let i = 0; i < INITIAL_SEEDS; i++)- Loops 20 times (INITIAL_SEEDS constant) to create the initial crystal formation
seeds.push(createSeed(random(width), random(height)))- Creates a new seed object at a random position and adds it to the seeds array