Skip to content

$ cd .. experiment code

2D raycasting vision simulator

Move your mouse over it, or leave it alone and watch the light wander. Drag the grey bars to change the room. On a phone, tap where you want the light to go.

Every frame the light sends out rays in all directions. Each one stops at the first thing it hits, and whatever the rays reached is what the light can see. A lot of games decide what a guard notices, how far a flashlight reaches, and where the fog of war lifts this same way.

Nothing here is really being lit. It’s a list of distances that happens to look like a shadow.

Slide the rays down and the edges go blocky. Slide them up and they go smooth, and it costs more. A game has to pay that for every light and every enemy at once, so the slider is really a budget.

$ cd ..