Workshop › Pool › Step 3 of 33
Every ball is the same kind of object: a position, a velocity (zero for now), a color, a number, and whether it is the cue
ball. ball(...) builds one. All balls will live in one array, balls, so the physics can treat them alike; cue is a
second name for the white one.
```js
const R = 9 // ball radius
const CUE_START = { x: 130, y: 160 }
let balls // { x, y, vx, vy, color, number, cue }
let cue
const ball = (x, y, color, number) => ({ x, y, vx: 0, vy: 0, color, number, cue: number === 0 })
function rack() {
cue = ball(CUE_START.x, CUE_START.y, '#f8fafc', 0)
balls = [cue]
}
function reset() {
rack()
}
reset()
```R is the ball radius; CUE_START is the cue ball's spot.ball is an arrow function that returns a new object. The object is in parentheses so the braces are not read as a
function body. { x, y } is short for { x: x, y: y }; cue: number === 0 is true only for number 0.rack puts the white ball on its spot and starts the balls array with it. reset sets up a new game and runs once at
the start.const BOTTOM = 280 write the new lines, from R down to reset.reset() just above the last line, requestAnimationFrame(loop). Press Run.Skills: Arrays and objects, Functions