Classifying & Labeling!

As I mentioned in the last post, much of what is going on right now is adding more information and context to the maps. With this information I can label the different entities on the map. I just started doing that, and although there are some challenges to overcome still, it looks like it can work satisfactory. I've taken continents, oceans, lakes, and islands so far, and given them "names". (It's all dummy-data so far, but that's beside the point at this stage). Finding the location to put the labels is not necessarily as trivial as one would expect though. Finding the "middle" of any kind of shape is not difficult in itself, but most algorithms are very time-consuming when working on such large amounts of cells. So I ended up scaling the algorithm itself, offering higher precision for smaller entities, and lower precision for the larger ones (like large oceans).

Challenges include labels that overlap each other. For instance, cities might be located on small islands, and then the label for the city name will crash with the label for the island name. These are things I'm going solve going forward. Also, all the labels are pretty plain and horizontal at the moment. When I start to label rivers for instance, the label could/should curve, and be angled adjacent to the river angle. Again, things that will be solved eventually.

Labels and identification of map entities might seem like a small thing when looking at the map below. But for the underlying system it's huge, and opens all kinds of doors. So, yay!

Islands & Lakes!


Pixel details, and a first version of smarter Cities.

Pixel details

Up until now, land has been land, and water has been water. To create more believable maps, with further customization possibilities, that sadly does not suffice. The filters that are being applied need more details about the geography to make smart decisions. I've added a few "Scanning" filters that basically tags each pixel in the map with additional information. Now each pixel knows the following:

  • What is my altitude? Am I above or below sealevel?
  • Am I in a river?
  • Am I on land, but next to a river? (A riverbank)
  • Am I along a coastline?
  • Am I in a lake?
  • Am I in an ocean?
I plan to add more information at later stages, - as this is fundamental to tailoring content.

Smarter Cities

Previously, when I generated city names, I had no way of making sure that the city names were fitting for their location. Now I can make sure that City 1 should be along the coast. Since I know this, the city name generator can now delegate its work to the specialized coastal-city name generator. No longer will the super-secret city of the pirates "Skullport" be located way up in the mountains :)

Refactoring, cleaning code, and battling high memory usage!

A little history...

This project started as nothing more than testing some noise-generation algorithms. In fact, even the Visual Studio project was called "TestProject". From there on as new ideas manifested, code began to take form. But my mental image of the code was still that it was just something that I wanted to try out, because it could be cool. So alot of code sprang forth as proof of concepts, with many try & fail iterations on most features. After a while, things settled and I started building further on what I had. The problem was that I never really took the time to clean everything up, refactor, and improve. I'm a huge fan of clean code, and  at some point I tried to reduce cyclic complexities and statements per method. However, about halfway through the code I  realized that when dealing with such computation-heavy code, cleaning up the code created a huge performance overhead. In most everyday projects it's still worth it, but not here. Performance is a key success factor, and it's still too slow for my liking. But alas, further performance optimization has been put on the backburner.

Anyway, without focusing on "clean code" specifically, I've refactored and beautified the code significantly over some time now. The next problem was trying to cope with huge memory usage. It has never been a goal in itself to use as little memory as possible, but I felt at some point the usage was ... Well, a little extreme. I've taken steps to reduce memory usage somewhat, replacing huge array copies with pointers and unsafe code where it seems reasonable. Memory usage is down, but it still chews through quite a bit.

All in all, today I am happier. Not completely content, but happier.


Deciding how to distribute the software.

I've spent a few hours contemplating on whether a first version of the software should be distributed through thick desktop clients, or on the web. I concluded that there was no obvious winner, and that there are several pros and cons to both alternatives.

  • Desktop client
    • Pros
      1. Functionality available everywhere.
      2. Rapid production of maps, - dedicated cpu and no waiting on others.
      3. Less personal bandwidth usage.
    • Cons
      1. Personally I'm less experienced in creating desktop clients (Especially UI).
      2. Software is bound to be updated rapidly in its first incarnations. Extra work to implement auto-update functionality.
      3. Not platform-independent.
      4. Software is cpu and memoryintensive. Old hardware might have trouble handling the requirements.
  • Website
    • Pros
      1. Pretty experienced with technology.
      2. Platform-independent.
      3. Very easy deployment. Updated website is immediately available for everyone.
      4. Software runs on a server with enough juice to run the software.
      5. Easier to detect errors in the software.
      6. Better general overview of the userbase (How many maps are created daily, for instance).
      7. Can easily apply trending to the software usage, to analyze where future effort should be focused.
      8. A community around the software can be embedded into the website seamlessly.
    • Cons
      1. Possibly longer map-generation time, if many users generate concurrently.
      2. More bandwith usage, as end-users have to download mapfiles.
      3. You have to be online to use it!
      4. I'll have to pay for hosting :)

In the end I decided that to start with, I'll be going with the website. Further down the road, I also want a feature-rich desktop client where you can turn and tweak all possible settings though. But the website alternative offers me the most at early stages. At least that's my opinion. (Yes, you're entitled to your own!)


Out of hibernation

So, this blog has been in hibernation for quite some time. So has work on the project, unfortunately. It came to a point where it took a little too much of my time, and some parts of it was quite frustrating. Other excuses include a few addictive games, moving the family to a new house, and a new job.

But, to the point. It's out of hibernation. I've decided that what I have now has potential, and already it might be worth something to someone. So I've shifted my focus slightly. I've started creating a web page so that everyone can try out what's already there, and pitch in their ideas for future stuff. I'm convinced that this will fuel motivation to keep going.

I've also been tidying up some of the map generation code. Parts of it was a bit messy, due to the pure nature of "try and fail" with different algorithms and functionality.

Can anyone recommend a web host that supports ASP.NET MVC 4, and has no shortage of CPU power and RAM? Creating these huge maps is a pretty taxing process ;-)

I promise to stay in touch while creating the website, and of course I'll inform everyone the very minute it's up and running!



A multi-flavoured mountain kingdom of dwarves

Name generation is underway, and it's time to show off some of the results so far. In addition to generating city names, I'm also dabbling into fantasy "languages". The languages are so far very basic, and not all words roll naturally off the tongue. As with everything, it's a work in progress.

The images shown below depict a region of a mountain kingdom. I asked in an earlier post what would constitute good city locations. These images are not generated with the default city placement rules, - but rather it's a test to weigh inland high-altitude higher. (Dwarves, anyone!?).

Kingdom with Language 1

Kingdom with Language 2

Kingdom with Language 3

Kingdom with Language 4


Easter update!

So, it's easter!

I have been rather busy at work lately, so progress has been rather slow. This update comes from my tablet, in a cabin far from the city. Technology is amazing. Anyway, what's going on in these fictional worlds? City placement has seen significant improvement. They now appear in locations that seem very reasonable. I am also looking into city name generation, as well as road connections between the cities. Once the name generation framework is complete, rivers, coastlines, forests and mountains will start getting names as well.

Once that is done, I want to track down some better textures for mountains and deserts, as well as some better city icons. Perhaps some of you readers want to contribute with something here? Would be appciated.

And once THAT is done, I am going to start preparing for an alpha release! Excited? Yes, me too.

But for the next days I will be busy relaxing and eating well!


A couple of city examples

I just wanted to keep everyone updated. I'm still dabbling with cities, and their placements. There's progress, and although I'm not satisfied yet, I'm optimistic!

Last addition is some minor adjustment to rivers, more refined city placements, city categorization, and city labels. I still have to make certain that cities of different categories do not come too close to each other, and the different coastal city categories need alot more work.

I'm also going to add more metadata to the underlying map, which will be very beneficial for search & pattern algorithms in the future.

Continent with cities and rivers

Our familiar continent, let's call it Utopia!


Placing cities. It's fun and annoying at the same time.

I've been trying to place cities lately. And although it's fun and offers me some personal pleasure, it's also quite annoying. First of all, it's quite demanding on those milliseconds. The map has metadata on which pixels are coastal pixels, which pixels are along a riverbank, which pixels are land pixels, and which pixels are water pixels. Beyond that, there's just not alot of metadata (I'm betting good money that I will invest time in improving this!), so we have to search and approximate alot. In trying to weight what would make a good city location, there are alot of magic numbers...

If you didn't know already, I hate magic numbers. They make no sense to anyone except me. Even future-me won't find them very logical. And the thought of that makes me sick. But alas, that's the sad truth at the moment. I need some magic numbers to form thresholds and boundaries. I didn't plan to rant over the source code here, but I'm not proud of this part. Don't get me wrong, the current [in progress] result is OK, but it's not really maintainable in the long run. Uncle Bob, or more formally Robert Martin, would literally cringe if he saw it. So needless to say, I'm going to spend some time refactoring and fixing it. I've tried to keep a focus on performance in this project, and performance doesn't always go hand in hand with clean code (sadly). But I'm going to sacrifice a few hundred milliseconds to clear my conscience. I aim to be a craftsman after all.

And that concludes today's rant...

I'll post some screenshots instead. The icons used for the cities ... You can discuss them, sure. But if you think about it, you'll come to the realization that they aren't the pillar of importance here.

Continent with a dry climate

Island with a dry climate
Continent with a more temperate climate
Island with a more temperate climate


Blazing ahead - City placement

So, I haven't written anything for a little while. I've been busy. With other pressing matters, kids with the flu, but also with working on my project. I've experimented with several different themes, which except the base geography, creates very different effects. The outcomes are totally unique. I can like that! It means that some of the things that I set out to do are actually coming together. The greatest challenge in many regards is actually finding decent seamless textures! I'm no artist (which is part of the reason I started this project in the first place), so my own sorry attempts don't cut it.

After this "multi theme prototyping phase", I want to take a step back, focus on one theme, and create every map layer for that one theme. The next challenge is... drumroll

City placement

Cities and towns will be a layer of the map that you can choose whether to generate or not. I understand that not everyone will find automatically generated cities useful, - but I would, and as such, I'm doing it!

I'm currently in a phase where I'm trying to come up with a decent algorithm for finding suitable places for cities. I'm probably going to base it on the algorithm that finds river locations, with some modifications of course.

But I need your help.

What describes a good city location? Where are cities normally located? Cities might have different size, - can we generally say the likelyhood that a large city will form in a specific location? Or a small town? What should be the minimum distance between two cities, as a general rule?

These are questions I need help with finding the answers to, to create an algorithm that produces city locations that are believable. Take into account that the maps will seldomly be 21st century maps. Fantasy maps are most often of the  medieval sort, although they don't necessarily have to be.


I want to consolidate some of the major points written in the comments here. I am going to group the points made, into two groups:

  • Geographic
  • Sociological / Demographic 

In the Geographic group lies the most obvious and visible requirements.

  • "Near water" - probably the easiest requirement to check for. At a river mouth, a river fork, a bay, or a coastal point. 
  • "Mountain pass" - most likely not the largest cities, but strategically placed ones. Most likely very secure. 

In the Socialogical / Demographic group lies more indirect requirements that may have a large impact on the bigger picture.

  • "Trade routes" - smaller towns may form naturally along major city trade routes, especially if the area is lush and abundant with food.
  • "Cultural centers" - Harder to implement as an initial requirement, it could be interesting to attempt to plot major cities first, then perform a second algorithm, using the large cities as cultural centers, to sea how lesser cities and trading routes form in their vincinity. Implementing this is quite some way down the road though.

There are more things to consider, but unless someone suggests specific ways to put them into an algorithm, I think I have more than enough to start with. Excited!


Moving into the water.

I've just added texturing and blending to the oceans. The effects are intentionally subtle compared to those on land, but I still believe they definitely serve their purpose. I'm showing off a continent using the latest effects. The image is 2048*2048 pixels, so click on it to see it in its native resolution.

Generated map

There are exceptionally good cartographers and artists out there, and I am pretty sure computer generated graphics will never be on par with those creations. However, when it comes to creating topology and continental shapes, this is already way past what I would be able to do manually.


Blending different layers.

So, I took my precious "Forest island", and turned up the temperature a bit. I'm currently blending a "grassland" layer (default background for this theme), an "arid" layer, a "mountain" layer, and lastly a "forest" layer. The forest layer has a reduced blend opacity in this example, so that the island appears more arid and dry.

Hopefully this shows some of the potential behind the software, - I'm definitely excited!


Starting with theming!

I just wanted to quickly show off the first attempts at theming the landmass. So I started with a familiar look. Grasslands, forests, and mountains. I've left the oceans alone for the moment, and focused on the land. Keep in mind that this is the first iteration of many to come, but I have a good feeling after coding a few hours. I present,  "Forest island".

I will come back in a later blog post with technical details and the how-to's, once I've refined the techniques and experimented further.


There are forks in my river!

It's been a while since the last update. There are several reasons for this, all of them unrelated to my project. But finally, I have been able to find some time to continue my work. I showed off some river examples earliar, and both commenters and myself thought it would look better if rivers had tributaries, like real rivers almost always have. So that's what I've been working on latelty. It's not 100%, there are some occasional weird artifacts, but largely I'm happy. Here are some recent screenshots of rivers.

I'm closing (or shelfing, as I will most likely come back to them later!) the chapter of rivers for now, and I'm starting work on different parts of the map generation, - the themes. I hope you all like the current look of the rivers, - and keep in mind you'll be able to adjust their curvation, tributary frequency and other things yourself, once I'm done-done!


Decisions, decisions...

Latest progress

Lately, I've been continuing my work on river generation, and currently I am working on tributaries. I'll post some screenshots soon, when I am happy enough with the results.

Planning ahead

Beyond that, I've done alot of thinking. I've been putting it a bit off, but recent comments spurred the process forward, and forced me to think more thoroughly on what I want to produce. I'm leaning more and more away from creating maps that focus heavily on realism. The plan was always to create something that would primarily be useful as game worlds and tactical roleplaying maps, - basically fantasy maps. So with that in mind, I've decided to produce maps of different sizes, and with different pre-defined themes. (Pre-defined does not mean that new themes won't be added, they definitely will).

Theme could be for instance a "parchment theme", as shown below.

Another theme could be an "earthlike theme".

A third theme could be something like this.

Now, even if you would have to select a theme, there will still be quite a few options to tweak, to create the kind of map you want, for that given theme. The exact specifics of what will be user preferences is yet to be decided, but I'm coding most things to be customizable.

If you already have themes in mind that you would find interesting and useful, - maybe something the internet is not already littered with, please let me know!

(The images linked here are not mine, I only wanted to display them as good examples of what I might want to do!)


The evolution of rivers

Just a short update that shows off usage of what I've called the "river curve weight factor". Some of you mentioned that you thought the rivers were too curvy. So I've made multiple configurable options for rivers. The curve weight factor being one of them. I've added an animated gif that shows the factor in action, with the values 1.6, 1.4, 1.2, 1.0, 0.8, 0.6.

What do you think?


Clarifying a couple of things

Over the last week or two, I've had this nagging feeling in my stomach. The feeling that many of the readers might have misunderstood what I am trying to do here.

I'm just going to spill it; For those of you who think I am making a new feature rich map editor, where you can specify each and every little thing... I'm sorry to disappoint you, but that's not it!

There's already a product out there that's good if you're looking for this kind of thing. I haven't tried it myself, but popular opinion seems to vouch for its quality. And that's Campaign Cartographer, which you can get at ProFantasy's web site.

So, back to my project. What am I trying to make? I'm trying to make a product for the lazy ones, for the ones who suddenly get the urge to play something in a new world setting and need the world now, and for those of us that aren't artists and want a good basis to found our game world on.

The first release of this product will be a web-based one-click creation process. A truth with minor modifications (you might have to check some checkboxes, and make some choices), but that's the jist of it.

You heard right. I want you to visit a web page. I want you to make some choices, and I want you to click a button. In return, I want to offer you a world setting.


Rivers in "Alpha"

So, rivers are in what I'd call an alpha stage right now. They need finetuning to look better, more natural, and with features (real deltas, mid-river islands, varying river width), but the harder parts are done. At least, I believe so. Unless everyone thinks they look like shit, of course. This is a short post, I just thought I would show a couple of examples of what you can come to expect.

Feedback is very much appreciated, as rivers are very hard, and I want to get them right!


Those darn rivers

For a while now, I have been implementing different approaches to river-generation. It's been pretty tricky, and there's been a lot of failures. But now finally, I seem to be on the right track. (Who knows what tomorrow brings though. My pillow insists on pitching me "good" ideas!)

It's not by any means perfect yet, but at least I feel like I am getting somewhere. I thought I would try to explain  my current approach, and why some other approaches had to be discarded.

So, what points are important for me?

  • Algorithm performance. Handcrafted maps do not have this challenge, but tools that will be available online definitely do. Complete maps of decent size should be generated within seconds.
  • Rivers need to have twists and turns that look somewhat "realistic" (Note the quotation marks here; Not really sure what realistic means. Looking at some real-world maps, rivers can pretty much look like anything!). 
  • Rivers need to follow some rules. An example would be that all rivers need to end in a body of water. (lakes or the ocean). Another rule is that two rivers can never cross each other. They should converge to one (larger) river. 

My approach

I'm not going to describe all the approaches I tried and failed with. That's really not what I'd like to focus on.

Let's just say that realistically forming rivers from mountain tops, and continually going downhill, always searching for the steepest descent until we reach bodies of water, is .. just .. too .. darn .. slow.
It works sufficiently for 1024*1024 maps. But traversing like this on 8192 * 8192 maps just does not work.  Sorry. I might end up offering  this approach for people who have extremely good time

So what did I do?

With heightmaps as my basis, I wrote an algorithm that searches for bays/coves in the landscape. I decided these are among the locations that I will want cities in the future, and also where I want rivers to end up. From these locations with the help of the "bay algorithm", I can find optimal angles for the river mouth. Rivers have random length, but their starting point should be along the axis of the river's optimal angle. (This angle is shifted if the starting point turns out to be in water). 

The river curving itself is made through the use of Bezier splines. The pro's of using these is that the river curving will look natural without doing alot of computing (it's fast!). The largest drawback is that you cannot easily foresee all the points along the river before it is generated. So, even if a straight line from the river mouth to the river start point only crosses land, the curving river might overlap with water.

If this is the case, I search for a new start point, and I try generating again. At the same time, the river length is gradually decreased until the curving river only crosses land. In some cases though, the algorithm decides that a river does not fit, and it gives up. These are often corner cases involving the corners of an image, an island, or very thin stretches of land.

Once I've found a suitable river path, I apply another algorithm that performs some basic erosion around the river, so that it lowers its surrounding terrain.

I'm going to show some screenshots soon, I just want to fix some tiny problems first. Until then.


Template examples

So, I thought I would post two simple examples of how different color templates (in their simplest form) can make the same base map look quite different.

After creating the heightmap, I have data that for each point in the map, has a value between 0.0 and 1.0. When dealing with templates, I multiply these values with 255. This seems to be an acceptable detail range for color mappings. (It basically means that one template can offer 255 different colors for a map).

The next step is adding blending functionality, so that multiple templates can be layered on top of each other. The templates that are shown here are also ignorant when it comes to internal positioning. They process data values in the same manner, whether the point is on the edge of the map, or in the center. But that is definitely not necessary, and templates can be used for so much more, which I'll show soon!

Beyond black and white

I'm currently experimenting with color templates (or Palettes if you will) to create distinguished looks for the maps. Screenshots are coming very soon, there's just some tidying up left before it's presentable.  Beyond that, I'm interested in finding out what people would find useful to have in an autogenerated setting.

I'm thinking:

  • Cities
  • Climate zones (visualize this, somehow)
  • Rivers
  • Mountains 
Anything else that seems important for the map portion of the project?

Lore, Naming generators ++ comes at a later stage.

Algorithms for finding decent city locations in an random environment is going to be challenging, I think. Rivers are much the same; Quality rivers that look good are challenging. But that's half the fun, and part of what keeps me motivated.