Implementing a some game graphic concepts in Go, using ebiten 2d graphics library. Thanks to @hajimehoshi for support. Examples are hosted at jsgo.io. Latest version here: https://jsgo.io/kyeett/2d-vision
Heavily inspired by Red Blob Games' article on 2D visibility. Also found this excellent wikipedia article on Visibility polygon)
The code in this library is quite messy. Use with care :-)
Simple algorithm. Send rays in all directions. If it intersects with one of the lines (walls or boxes), select the point that is closest to the player and draw a line to there. These lines used as vertices for triangles that are removed from the shadows.
Calculate the angles to the corners of all objects, and do the ray cast only in that angle.
Note: At first, I had a lot of problems with the rays stopping ON the corners. I solved this by sending two lines per corner, with a small offset to the angle in both directions. It works well, but doubles the number of lines. I'm not sure if this is the right approach.