10 - A cone of vision

Drag the ring to reposition the guard, or the rectangle to move it out of sight.

cast(originX, originY, directionX, directionY, maxDistance, options)
Fired once per angle across the cone, it gives the shape the guard can actually see: the polygon its endpoints trace, closed back on the guard itself.

lineOfSight(startX, startY, endX, endY, options)
Answers whether anything stands between two points. Being seen is two separate questions, and a guard that asks only the first one sees through walls.

The rectangle is tested at its four corners and its center. One point is enough to be spotted, which is why the cone turns red while most of the box is still hidden.