Workshop › Conway's Game of Life › Step 23 of 32
From a point in canvas pixels to a cell: divide by the cell size and round down. Points outside the grid give null.
```js
function cellAt({ x, y }) {
const r = Math.floor((y - TOP) / CELL)
const c = Math.floor(x / CELL)
return r >= 0 && r < ROWS && c >= 0 && c < COLS ? { r, c } : null
}
```{ x, y } in the parentheses takes x and y out of the object passed in.Math.floor rounds down: x = 85 gives 85 / 8 = 10.6, so column 10. For the row, TOP is taken off first.{ r, c } is short for { r: r, c: c }. Outside the grid it returns null, "nothing".Write cellAt under toCanvas, above function update() {, with empty lines around it.
Skills: Keyboard and mouse input
← Where is the pointer? Click a cell →