Skip to content

HTML application that keeps a known "player" shape completely inside of any arbitrarily-shaped "map" using SVG

License

Notifications You must be signed in to change notification settings

amacle/map_boundary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

map_boundary

A HTML application that keeps a known "player" shape completely inside of any arbitrarily-shaped "map" using SVG.

Here, the "player" shape is a circle that follows the mouse cursor, and the "map" is a closed SVG path. When the cursor moves outside of where the player can completely fit inside of the map, we want the player shape to follow the cursor by moving along the inner edge of the map in such a way that the shape is still completely contained within the map boundary.

An effective way to achieve this is to generate an inset parallel curve one player-radius away from the original map path. If the mouse cursor is inside of the offset shape, the player shape can follow the cursor normally. If the mouse cursor is outside of the offset shape, we instead have the player shape snap to the nearest point on the offset map's edge relative to the mouse cursor.

Interactive demo

(Note that the demo presently doesn't work in Firefox, as the needed SVGGeometryElement hit-testing functions have yet to be implemented into the browser.)

About

HTML application that keeps a known "player" shape completely inside of any arbitrarily-shaped "map" using SVG

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages