Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the diamond square fractal algorithm infinite

I'm trying to generate an infinite map, as such. I'm doing this in Python, and I can't get the noise libraries to correctly work (they don't seem to ever find my VS2010, and doing it in raw Python would be way too slow). As such, I'm trying to use the Diamond-Square Algorithm.

Would it be possible, in some way, to make this technically infinite?

If not, should I just go back to attempting to get one of the Python noise bindings to work?

like image 312
The Communist Duck Avatar asked Feb 12 '11 12:02

The Communist Duck


2 Answers

This can be done. Divide up your landscape into "tiles", and apply the midpoint displacement algorithm (as I prefer to call it) within each tile.

Each tile must be big enough so that the height at one corner does not significantly depend on the height in another. In that way, you can create and destroy tiles on the fly, setting the height at newly appearing corners to an independent random value.

That value (and the randomness within the tile as well) must be seeded from the tile's position, so that you get the same tile each time.

like image 75
Thomas Avatar answered Oct 04 '22 16:10

Thomas


The latest version of the noise module (at http://pypi.python.org/pypi/noise/1.0b3) mentions that it "fixed problems compiling with Visual C++ on Windows" - you might want to try it again. It installs and works properly for me (Python 2.7.1, MinGW, Windows 7).

If you arrange your tiles in an x,y grid and seed the random number generator for each tile like random.seed((x,y)), then every time you return to the same patch of world it will re-create the same terrain.

With the diamond-square algorithm, two sides of each tile depend on the adjoining tiles; however the dependence does not propagate all the way across the tile. If you let each tile depend on the tiles preceding it (ie above and to the left) and write a create_fake_tile function which assumes that all the preceding-tile values are 0, you get a "bad" tile in which the right column and bottom row are the correct values on which the next tile depends. If you draw each screen starting with the tile row and column preceding the first row and column on screen, then the visible portion of your world will be correct.

like image 33
Hugh Bothwell Avatar answered Oct 04 '22 17:10

Hugh Bothwell