Keith Vetter 2002-11-11 - This program draws mountain landscapes using fractals. It is based on an article at [1].

The fractal algorithm it uses is a fairly common one. It takes an equilateral triangle (actually two of them that together form a parallelogram for easier coding) and assigns heights to each vertex. For each iteration level, it subdivides every triangle into four similar, smaller triangles. The vertices of the new triangles are assigned height values based on the average height of the neighboring vertices with a random deviation added in. This random deviation is smaller for deeper iterations, thereby giving the fractal quality of scaled similar details.

Generating the fractal mountain is only the first step, you also have to display it. For hidden surface removal it uses a painter's algorithm (back-to-front drawing). The basic color is based on altitude: blue for below sea level, green up to the treeline, white above the snowline and some shade of green to brown in between treeline and snowline. The brightness of the color is determined by the angle of incidence from a fixed light source.

KPV 2002-11-12 -- added two new features: you can vary the altitude of the water level; and redraw does some fancy footwork to keep the same mountain data even if you vary the number of iterations.

The mountains this makes are so nice that I wanted to look at them from all directions. So I put together some code to display the mountain using TkOGL (over on the OpenGL page). Unfortunately I don't know much about OpenGL so the lighting doesn't work right, and it could probably be optimized better for OpenGL. But its nifty nontheless. GL Fractal Mountains