Workshop › Pinball › Step 6 of 42
Draw the ball
What we are doing
Now we draw the ball wherever ball says: a filled circle of radius R.
```js
ctx.fillStyle = '#e7e5e4'
ctx.beginPath()
ctx.arc(ball.x, ball.y, R, 0, Math.PI * 2)
ctx.fill()
```
What it means
arc(x, y, r, start, end) plans a circle around (x, y) with radius r, from angle start to end.
- Angles are in radians:
Math.PI * 2 is a full turn, so this is a whole circle.
fill() fills the planned shape with fillStyle.
Your turn
Inside draw, after the for loop that draws the walls, write the four lines.
Skills: Drawing on a canvas
← A ball in the lane Move by the velocity →
All steps
- Paint the table
- Draw one wall
- A list of walls
- The game loop
- A ball in the lane
- Draw the ball
- Move by the velocity
- Launch with Space
- Gravity
- Does the ball touch a wall?
- Push the ball out
- Bounce off the wall
- Small steps and a speed limit
- Ready or playing
- The next ball
- Three bumpers
- The ball meets a bumper
- A bumper kicks
- A score and a fresh start
- Points for every hit
- Remember which bumper was hit
- Light it up
- Lit for a moment, points once
- Two flippers
- Where is the tip?
- Flippers stop the ball
- Which keys are held?
- Which way to turn
- Flip!
- A moving wall
- The flipper throws
- Three balls
- Balls left and game over
- Play again
- Remember the best score
- Launch on letting go
- Pull the spring
- Show the spring
- Two thumbs
- Pull with a finger
- Tap to play again
- Build it yourself: slingshots