Created
April 11, 2021 03:30
-
-
Save joehonton/6172ca5cd03af3626adf3bd13e0ed9e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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