Workshop › Pool › Step 7 of 33

An aim line

What we are doing

A shot goes in a direction, an angle aim in radians. A thin line from the cue ball shows it. Trigonometry turns the angle into x and y: Math.cos(aim) is how far right, Math.sin(aim) how far down, for each unit along the line.

```js
let aim // angle of the shot, in radians

  aim = 0

  ctx.strokeStyle = 'rgba(255, 255, 255, 0.6)'
  ctx.lineWidth = 1
  ctx.beginPath()
  ctx.moveTo(cue.x, cue.y)
  ctx.lineTo(cue.x + Math.cos(aim) * 400, cue.y + Math.sin(aim) * 400)
  ctx.stroke()
```

What it means

Your turn

  1. Under let cue write let aim ...; in reset, under rack(), write aim = 0.
  2. In draw, under the felt's fillRect, leave an empty line and write the six line-drawing lines.

Skills: Drawing on a canvas

All steps

  1. The room
  2. The table
  3. The cue ball
  4. Draw the balls
  5. The rack
  6. Numbers on the balls
  7. An aim line
  8. Turn the aim
  9. A shot is a velocity
  10. Roll
  11. Friction
  12. Cushions
  13. Aiming and rolling
  14. Hide the aim while rolling
  15. Count the shots
  16. Balls that touch
  17. Swap the push
  18. Six pockets
  19. In the pocket
  20. Scratch
  21. Balls left
  22. Clear the table
  23. Choose the power
  24. A power bar
  25. A slingshot
  26. Press to aim
  27. Pull back and let go
  28. Smaller steps
  29. Predict the hit
  30. Draw the ghost ball
  31. Where the hit ball goes
  32. Your best
  33. Build it yourself: two players