Workshop › Klondike Solitaire › Step 1 of 40
The classic card game, built from piles. Thirteen piles in one object, overlapping columns, the rules as pure functions, tap to move, drag and drop with a grab offset, a win check after every move, and undo with a stack of snapshots.
Every card game needs a table. We find the canvas, take its 2D context (the pen), and start a loop that paints the whole canvas green about 60 times a second.
```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')
function draw() {
ctx.fillStyle = '#166534'
ctx.fillRect(0, 0, canvas.width, canvas.height)
}
function loop() {
draw()
requestAnimationFrame(loop)
}
requestAnimationFrame(loop)
```getElementById('game') finds the 480×560 canvas; getContext('2d') gives the pen, ctx.draw fills a rectangle as big as the canvas with dark green, starting at the top-left corner (0, 0).loop draws and books itself for the next screen refresh with requestAnimationFrame; the last line starts it.Write the code under the three comment lines, then press Run.
Skills: Drawing on a canvas, The game loop