Something I really like with programming is generating stuff. A while ago, @bram@social.wxcafe.net explained how he generated fictional maps. (However his method wasn't the one I'll be using here.) In particular, he gave me a link to a really cool explanation (it contains a link to their code and another explanation) about map generation. It's been a while, but some people, who love generating pictures have motivated me to do some progress. For now, I haven't made much, but the things I've done are still really cool and can be adapted to a lot of things already.
So, what do I do ? First of all, I fix the dimension in which I'll work, and generate "a few points" in it, with a simple random.randint
(the fact that this is an int is not really important, except for Pillow). Then, using scipy.spatial
, we make a Voronoi grid from these points. It will compute the "area of influence" of all these points, which is pretty cool.
However, the points we made at the beginning are too random, so we drop them, and take the centers of the voronoi regions instead. This a Lloyd's relaxation. And we repeat it to smooth it further. The result isn't perfect, and we could do a lot more Lloyd's relaxation steps, but it's already nice enough and I don't wanna spend too much computing time on this.
The next step is generating hill. How do I do ? Well, I've got a maximum elevation (100, arbitrary value), so I select a random elevation in the range, and make a random tile be this high. To smooth the terrain, I browse the neighbouring tile recursively, until thay are far enough, and set their elevation depending on the radius of the hill and their distance to the summit.
Finally, I've played with the color, to generate a more diverse images, and even gifs !
So far, and I don't really generate maps, but I've implemented the basics (generation of the grid, and a few hills), and I've been able to have fun making some pictures and gifs ! I'll update the code, to integrate more map-related stuff later.
Link to my code is here.
Comments
No comments yet. Be the first to react!