So far you've used functions p5.js gave you: circle(), rect(), background(). Now you write your own. A function is a named block of code you can run whenever you want, and each time you can pass it different values — called parameters.
The magic: write drawHouse() once, then call it five times with different sizes and colours. A whole miniature village in five lines.
Five houses, one function. Click the canvas to add a sixth house.
function drawHouse(x, y, size, roofCol)drawHouse — what you call itx, y, size, roofCol — the ingredients that change each time{ } block — the recipe stepsdrawHouse(60, 215, 70, '#c0392b'), the values 60, 215, 70, '#c0392b' are called arguments — they fill in the parameters.
drawButton(x, y, label, colour) — called once for every button on the screen, with different arguments. The function is written once; the arguments change everything.
x = 475 — it'll be off-screen! Change createCanvas(420, 260) to createCanvas(520, 260) to fit it. What colour roof will you give it?drawHouse: a small dark rect near the top of the roof. It needs to use size so it scales with the house.drawHouse(x, y, size, roofCol, doorCol) and use doorCol in the door section. Update all five calls to pass a door colour.drawTree(x, y, size) function — a brown rect trunk and a green circle top. Place three trees between the houses.drawCloud(x, y) function using four or five overlapping ellipse calls in white. Place three clouds in the sky at different heights. Clouds near the top = smaller (they're "farther away").