INNER CODE UNIT · TypeScript
onMouseClick
jamesroutley/24a2 · src/engine.ts:379
function onMouseClick(this: CanvasIOManager, event: MouseEvent) {
if (!this._dotClicked) {
return;
}
const rect = this._canvas.getBoundingClientRect();
// cx and cy are the x y coordinates of the mouse click relative to the
// canvas
const cx = event.clientX - rect.left;
const cy = event.clientY - rect.top;
const offset = this._dotSize + this._gapSize;
// Iterate over all dot locations, and check whether the distance
// between the click and the dot centre is less than the dot's
// radius
for (let y = 0; y < this._gridHeight; y++) {
for (let x = 0; x < this._gridWidth; x++) {
const dx = this._dotSize / 2 + x * offset;