Pygame Landscape generator

Today I came across this page, which contain many interesting things, including some sections on generating landscapes in a procedural way. I'd been meaning to try this for a while and I finally got around to it.

The image shows a landscape, which I think looks pretty realistic. It was created after 7 iterations, which means it consists of 16,641 nodes (16,384 squares). At each iteration, the height of each node was randomly changes by a value that scaled with 2^0.8i, where i is the number of iterations. This seemed to give the right balance between a smooth and jagged landscape.

The hardest part was working out how to split each square into four smaller squares. In the end, I resorted to renumbering the nodes at every iteration, rather than trying to calculate which edges were associated with which square.

This has also spurred me to continue my Pygame 3D graphics tutorial. This landscape was created on an updated version that uses numpy and linear algebra, so is a lot more efficient at dealing with large objects. Next up - shading the surfaces in this updated version, and maybe adding some water. And then simulating an ecosystem, a meteorological system and an entire universe.

Below are the files required to generate and view the landscape. You will need to convert them all the .py files and then run 

displayWireframe.txt7.87 KB
wireframe.txt6.58 KB
landscape.txt1.7 KB

Post new comment

The content of this field is kept private and will not be shown publicly.