Workshop › Typing Rain › Step 4 of 33
The words will fall, so the picture must be drawn again many times a second. We pack all the drawing lines into a
function named draw, so one word repaints everything.
```js
function draw() {
ctx.fillStyle = '#020617'
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = '#7f1d1d'
ctx.fillRect(0, GROUND + 4, canvas.width, 3)
ctx.font = FONT
ctx.textAlign = 'left'
ctx.fillStyle = '#cbd5e1'
ctx.fillText('rocket', 40, 120)
}
draw()
```function draw() { ... } defines the recipe; it does not run yet. Its body is indented by two spaces.draw() with parentheses runs it. Each run paints the sky first, which wipes the old picture.Wrap all the drawing lines in function draw() { ... } (indented by two spaces) and call draw() after it.
Skills: Functions
← A word on the canvas A list of words →