This world-generator produces a landscape with rivers. Here's a screenshot. It's a kind of hierarchical refinement. Initially it starts with a grid of squares. Each square is subdivided into four triangles by two diagonal cuts. The landscape attributes of the triangles are determined from those of the square they are cut up from.
Then the triangles are fused to make new squares. Each new square consists of two adjacent triangles, one from each of two adjacent original squares. The sides of the original squares become the diagonals of the new squares. These new squares are thus tilted 45 degrees from the original squares, and each consists of two triangles. These new squares are thus half the area of the original squares. The landscape attributes of these new squares are synthesized from the landscape attributes of the two triangles they are made from. The result is that each new square is descended from two of the original squares.
This process of overlapping influence is what keeps the boundaries of the original quares from being particularly visible in the final map.
The above geometry is independent of the landscape attributes. This particular program uses attributes that describe the flow of rivers through the squares and, derived from those, the altitudes of parts of the square. Of course the details of how the attributes of one scale depend on the larger scale depend on both the meaning of the attributes and the geometry. They would likely have to be rewritten completely with a different geometrical structure.
Other landscape attributes could be chosen, generating quite different landscapes.
It might be pleasant to add trees, or use entirely different kinds of attributes to generate, say, an industrial complex.
The program also contains extensive code to check that the attribute mechanisms for splitting squares to triangles and fusing triangles to squares maintain the compatibility of the attributes of adjacent triangles and squares.
The code provided here is more a development snapshot and tech demo than a finished product.
It has code that is commented out rather than deleted.
Some of it is obsolete; some of it constitutes wishes for the future.
It's been tested on Debian Linux, on wheezy on a 32-bit Intel architecture and squeeze on an AMD64.
Controls are: cursor keys for movement left, right, forward, backward. 4 is to turn left; 6 to turn right. If I remember correctly, PgUp makes you taller, so you can see further, and PgDn shorter. I think 2 and 8 also did something -- possibly turning your head upwards and downwards? Taking any of this to extremes can get you in funny positions, perhaps seeing everything upside down.
The code is here.
It's written in Modula 3. Links to a free Modula 3 implementation can be found on the Modula 3 Wikipedia page. I've never tried it on Windows or Mac.
I'd like to extend this to other kinds of geometries.
I'd like to eliminate the edge of the world.
I'd like to extend the grid of the world after the world has been generated, producing more and more landscape to wander through.
I'd like to generate the world lazily, as needed, retaining the part of the world that is currently visible, but caching the rest, discarding it when memory gets full, and regenerating it as needed.
I'd like to maintain distant parts in lower resolution, again to limit memory usage and the number of triangles the graphics card has to handle.
I'd like to have more interesting landcape.
I'd like to be able to use irregular grids, or grids of triangles refining into triangles.
I'd like to make more efficient use of OpenGL.
The frame rate is terrible on my development machine.
And I'd like to have more interesting land than uniformly green stuff (except for altitude and fog) blending into uniform water.
Maybe roads, railroads, buildings, trees, fences.
But they should ideally be procedurally generated, too.
And you may notice I'm a terrible typist and proofreader.
Send me comments on this project, reports on typos, and anything else relevant.
-- hendrik AT topoi.pooq.com