Polygon Map Generation demo

来源:互联网 发布:linux ssh连接数限制 编辑:程序博客网 时间:2024/06/05 06:20

http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/


The simplest way to explore the maps is to click Random repeatedly. Try the various Island Shape, Point Selection, and View options.

Feel free to use these maps for any purpose, including commercial use. This is a map generator I wrote in 2010 for a game; I’m not working on it anymore, but all the code is available so that you can download and modify it for your own needs.

In a shape number like 85882-8, 85882 chooses the overall island shape and 8 is the random number seed for the details (random points, noisy edges, rivers). You can type in a shape number and press Return to generate that map. The details will vary based on the other options you’ve selected.

I wrote an article describing the algorithms, and how you can use all or some of the parts in your own projects. I generate island maps with constant slopes here, but you can use the same ideas for many different styles of maps. Notes:

  • Radial, Perlin, Square, Blob are about the island shape.
  • Random, Relaxed, Square, Hex are about how the map is divided up into polygons.
  • Using 4000 or 8000 points can be slow. I’ve tried 16,000 but Flash gets rather buggy so I didn’t put it in the demo.
  • The PNG output is 2048x2048, and draws the selected mode (biomes, polygons, 2d slopes, etc.). It’s slow. I don’t include the noisy bitmap dots so that you can more easily use this in your own projects.
  • The byte array output are a 2048x2048 height map, a 2048x2048 moisture map, and a 2048x2048 array of bit flags, which you can decipher by looking atexportOverrideColors in mapgen2.as.
  • The 3D slopes output is slow (I wrote this a long time ago, before GPU acceleration was generally available in browsers).
  • There are lots better ways to render the maps, but I haven’t explored them. For this project I was focused on the generation of structured maps.
  • I also implemented road and lava algorithms but didn’t include them in this demo.
  • The watershed detection algorithm is unifnished. I was hoping it would be useful for assigning territorial control. I will revisit it when I want to procedurally generate towns, cities, nations, histories, etc.

The code is open source, using the MIT license (allows commercial use). I put it up on Github. Sorry, it’s not designed to be easy to reuse. I focused instead on explaining the concepts in the article, so that you can implement the algorithms yourself. I did not implement the Voronoi algorithm; I used an existing library for this.

The original demo I posted in 2010 is here. Changes: I took out roads; I added PNG export; I added byte array output (e.g. height maps); I added control over the number of points; I added control over the distribution of points.

原创粉丝点击