# 3D Tunnel

This classic demo-coder's effect uses a very simple idea to split the entire display area into two lookup tables that can be used to quickly render a texture-mapped 3D tunnel.

## How does the effect work?

For each pixel on the display, we need to find an x-coordinate and a y-coordinate which can be used to look up a pixel on our texture. If you look at the screenshot of the tunnel above, you should be able to see that the texture wraps on to the walls like this:

The x-coordinate is directly related to the *angle* of the wall and
the y-coordinate to the *distance *down the tunnel. What we need are
two lookup tables - one that holds the angle for each pixel, and another that
holds the distance to each pixel.

## Calculating lookup tables

The lookup tables should be the same size as the window. For the sake of simplicity, it's a good plan to start with a square window (the screenshot at the top of this document is from a 512x512 window).