2D Lighting

In what follows is an algorithm for 2D lighting, as seen in the video games Super Meat Boy, and Gish.

Algorithm

You are given a light and some walls. The light is a point and each wall is a line segment. From the endpoints make a set of points. Order the points according to their angle relative to the light's position. Shoot a ray from the light towards each of these points. Determine the intersection point of the ray with each of the line segments if any. Keep the point that's closest to the light. These closest points give a polygon corresponding to the space that's lit.