Workshop › Pinball › Step 25 of 42
The pivot is fixed; the tip is FLIPPER_LENGTH away in the direction of the angle. Cosine and sine turn an angle
into a horizontal and a vertical part. Then each flipper is drawn as a thick blue line from pivot to tip.
```js
const tip = (f) => ({ x: f.x + Math.cos(f.angle) * FLIPPER_LENGTH, y: f.y + Math.sin(f.angle) * FLIPPER_LENGTH })
ctx.strokeStyle = '#38bdf8'
ctx.lineWidth = 10
for (const f of flippers) {
const t = tip(f)
ctx.beginPath()
ctx.moveTo(f.x, f.y)
ctx.lineTo(t.x, t.y)
ctx.stroke()
}
```a, Math.cos(a) is how far right and Math.sin(a) how far down a one-pixel step in that direction
goes. Multiplying by the length gives the tip's offset from the pivot.tip is written as an arrow function stored in a constant; it returns an object { x, y }.// Push the ball out of a segment... comment write tip, with an empty line after it.draw, under the bumpers' forEach block, write the flipper drawing.Skills: Drawing on a canvas, Functions
← Two flippers Flippers stop the ball →