1 function getMousePosition(event) { 2 const { clientX, clientY } = event; 3 const { top, left } = canvas.getBoundingClientRect(); 4 const x = clientX - left; 5 const y = clientY - top; 6 return { x, y }; 7 }
1 function getMousePosition(event) { 2 const { clientX, clientY } = event; 3 const { top, left } = canvas.getBoundingClientRect(); 4 const x = clientX - left; 5 const y = clientY - top; 6 return { x, y }; 7 }