setup()
setup() runs once when the sketch starts. Because this whole sketch is event-driven (nothing needs to animate every frame), setup() is where almost all of the important configuration and the first drawing happens.
function setup(){createCanvas(windowWidth,windowHeight);noiseDetail(2,0.6);strokeCap(ROUND);makeSand();initStones();}
Line-by-line explanation (5 lines)
createCanvas(windowWidth,windowHeight);- Creates a canvas that fills the entire browser window.
noiseDetail(2,0.6);- Configures Perlin noise to use 2 layers ('octaves') of detail with a 0.6 falloff, which controls how smooth vs. bumpy the noise texture looks.
strokeCap(ROUND);- Makes the ends of every line drawn afterward rounded instead of squared off - important for the rake grooves to look soft rather than blocky.
makeSand();- Calls the function that paints the textured sand background.
initStones();- Calls the function that randomly places the starting stones on top of the sand.