Workshop › Pool › Step 11 of 33

Friction

What we are doing

The felt slows the balls: every frame each ball keeps 98.5% of its speed. Multiplying by the same number every frame slows it smoothly, fast at first and gently at the end. Below a tiny speed it is set to exactly zero.

```js
const FRICTION = 0.985 // speed kept each frame

  for (const b of balls) {
    b.vx *= FRICTION
    b.vy *= FRICTION
    if (Math.hypot(b.vx, b.vy) < 0.05) b.vx = b.vy = 0
  }
```

What it means

Your turn

  1. Under COLORS write FRICTION.
  2. In update, under step(), write the loop.

Skills: Velocity and gravity

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