Workshop › Rhythm Lanes › Step 2 of 35
The first lane
What we are doing
There are 4 lanes, 70 pixels wide, centred on the canvas. We name these numbers and draw the first lane as a tall
strip.
```js
const LANES = 4
const LANE_W = 70
const LEFT = (canvas.width - LANES * LANE_W) / 2
ctx.fillStyle = '#1e293b'
ctx.fillRect(LEFT + 2, 0, LANE_W - 4, canvas.height)
```
What it means
LANES is the number of lanes, LANE_W their width, LEFT the empty space on the left: (400 - 280) / 2 = 60.
- The lane is drawn 2 pixels in from each side (
+ 2, - 4), so neighbouring lanes have a thin gap.
Your turn
- Under
const ctx = ... leave an empty line and write the three constants.
- At the very end, under the background lines, write the two lane lines. Press Run.
Skills: Drawing on a canvas
← A stage for the notes Four lanes with a loop →
All steps
- A stage for the notes
- The first lane
- Four lanes with a loop
- The hit line
- A function that draws
- The song as text
- From text to notes
- The clock decides where
- Draw the notes
- A clock that ticks
- The game loop
- Lanes that light up
- Keys for the lanes
- Show the keys
- Hit the closest note
- Close enough in time
- One press, one hit
- A message on the screen
- Say Hit
- Let the message go
- Perfect or good
- Keep count
- Missed notes
- Score
- Hits in a row
- The multiplier
- The song ends
- Stop the clock
- Accuracy
- The grade
- The results
- Play again
- Best score
- Lanes you can tap
- Build it yourself: a speed setting