Workshop › Pool › Step 25 of 33
Arrow keys are precise but slow. Most pool games use the pointer like a slingshot: pull back away from where you
want to shoot. pull(point) turns a point into an aim and a power, both from one vector: from the point to the cue ball.
```js
// Pull back from the cue ball like a slingshot: the shot goes the other way, harder the further you pull.
function pull(point) {
aim = Math.atan2(cue.y - point.y, cue.x - point.x)
power = Math.min(MAX_POWER, Math.hypot(point.x - cue.x, point.y - cue.y) / 6)
}
```Math.atan2(dy, dx) gives the angle of a vector in any direction: the reverse of cos/sin. The vector here goes from
the point through the cue ball, so the shot goes away from where you pull.MAX_POWER: pulling 60 pixels gives power 10.Above function draw() { write pull with its comment, and leave an empty line after it.
Skills: Velocity and gravity, Functions