Workshop › Sokoban › Step 7 of 29
Every tile is a 48-pixel square. A small tile helper paints one square, slightly inset; then every wall in the Set is
drawn with it.
```js
const TILE = 48
function draw() {
ctx.fillStyle = '#1c1917'
ctx.fillRect(0, 0, canvas.width, canvas.height)
const tile = (x, y, color, inset = 0) => {
ctx.fillStyle = color
ctx.fillRect(x * TILE + inset, y * TILE + inset, TILE - inset * 2, TILE - inset * 2)
}
for (const k of walls) {
const [x, y] = k.split(',').map(Number)
tile(x, y, '#78716c', 1)
}
}
```tile(x, y, color, inset) paints the tile at column x, row y: x * TILE pixels from the left, shrunk by inset
on each side. inset = 0 is a default when it is left out.for (const k of walls) goes through the Set. k.split(',') cuts '3,2' into ['3', '2'], .map(Number) makes
them numbers, and const [x, y] = names the two.// The classic ... write const TILE = 48.draw, under the fillRect line, leave an empty line and write tile and the for loop. Press Run.Skills: Drawing on a canvas
← Read the walls Center the level →