Workshop › 15 Puzzle › Step 6 of 27
A square is 90 pixels with a 6-pixel gap between squares. squareX(i) and squareY(i) give the top-left corner of
square i, with the board centered and a strip left at the top for text.
```js
const SIZE = 90
const GAP = 6
const LEFT = (canvas.width - N * SIZE - (N - 1) * GAP) / 2
const TOP = 60
function squareX(i) {
return LEFT + colOf(i) * (SIZE + GAP)
}
function squareY(i) {
return TOP + rowOf(i) * (SIZE + GAP)
}
```4 × 90 + 3 × 6 = 378 pixels wide; LEFT is half of what is left of the 400: 11.SIZE + GAP = 96 pixels further to the right, each row 96 pixels further down.return gives the result back.N line, write the four size lines.function draw() {, write squareX and squareY and leave an empty line. Press Run.Skills: Drawing on a canvas, Functions
← Row and column Draw one tile →