setup()
setup() runs once when the sketch starts. It's the right place to configure global settings like canvas size and color mode before any drawing happens.
function setup() {
createCanvas(windowWidth, windowHeight); // https://p5js.org/reference/#/p5/createCanvas
colorMode(HSB, 360, 100, 100, 100);
noStroke();
noiseDetail(3, 0.5);
updateLampBounds();
createBlobs();
}
Line-by-line explanation (6 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window.
colorMode(HSB, 360, 100, 100, 100);- Switches p5's color system to Hue/Saturation/Brightness (with alpha up to 100) instead of the default RGB, making it easy to pick warm hues and adjust brightness independently.
noStroke();- Turns off outlines by default so shapes are filled without a border unless stroke() is called again later.
noiseDetail(3, 0.5);- Configures how Perlin noise blends multiple octaves - this controls how detailed/textured the noise patterns look when sampled later for wobble.
updateLampBounds();- Calculates where the glass tube's edges are based on the current canvas size.
createBlobs();- Builds the initial array of LavaBlob objects that will animate throughout the sketch.