function getCoordinates(e) {
  let { clientX, clientY } = e
  // for touch event
  if (e.touches && e.touches.length) {
    clientX = e.touches[0].clientX
    clientY = e.touches[0].clientY
  }
  const { left, top } = e.target.getBoundingClientRect()
  const [x, y] = [clientX - left, clientY - top]
  return [x, y]
}
Gets the (x, y) coordinates of an UI event relative to its target,
e.g., canvas. Accounts for touch events as well as mouse events.