Workshop › Pac-Man-style Maze Chase › Step 2 of 42
Everything will move, so the picture is drawn again before every screen refresh (about 60 times a second). draw
paints the dark background; loop draws and asks for the next frame with requestAnimationFrame.
```js
function draw() {
ctx.fillStyle = '#0b1020'
ctx.fillRect(0, 0, canvas.width, canvas.height)
}
function loop() {
draw()
requestAnimationFrame(loop)
}
requestAnimationFrame(loop)
```fillStyle picks the color, fillRect(x, y, w, h) fills a rectangle; (0, 0) is the top-left corner.requestAnimationFrame(loop) asks the browser to run loop before the next screen refresh; loop asks again each
time, so it never stops. The last line starts it.Under COLS, leave an empty line and write draw, loop and the start line.
Skills: The game loop, Drawing on a canvas
← The maze as text Draw the walls →