Skip to content

Instantly share code, notes, and snippets.

@joehonton
Created April 11, 2021 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehonton/6172ca5cd03af3626adf3bd13e0ed9e2 to your computer and use it in GitHub Desktop.
Save joehonton/6172ca5cd03af3626adf3bd13e0ed9e2 to your computer and use it in GitHub Desktop.
const shapes = new Map();
shapes.set('triangle',
[{x:100, y:100},
{x:120, y:120},
{x:140, y:140},
{x:100, y:100}]);
shapes.set('quadrangle',
[{x:371, y:229},
{x:229, y:229},
{x:229, y:371},
{x:371, y:371},
{x:371, y:229}]);
shapes.set('pentagon',
[{x:550, y:450},
{x:455, y:519},
{x:491, y:631},
{x:609, y:631},
{x:645, y:519},
{x:550, y:450}]);
const el = document.querySelector('#canvas');
el.addEventListener('mousemove', e => {
for (let [name, polygon] of shapes) {
if (isInsidePolygon(polygon, e.offsetX, e.offsetY))
console.log(`Mouse is hovering over ${name}`)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment