setup()
setup() runs once when the sketch starts. Here it wires together the canvas and the two initialization helpers, keeping the startup logic short and readable.
function setup() {
createCanvas(windowWidth, windowHeight);
pixelDensity(1); // Keep pixel math simple & fast
initField();
}
Line-by-line explanation (3 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, using the browser's current width and height.
pixelDensity(1);- Forces the canvas to use exactly one pixel per CSS pixel (ignoring Retina/HiDPI scaling), which keeps the pixel-array math in drawMetaballs() simple and predictable.
initField();- Calls the setup helper that builds the offscreen low-resolution buffer and creates the metaball objects.