Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Generate image from non-image data (Godus like landscape)

So upon seeing images from Godus I was wondering how to generate a simple, non-interactive, 2D image with different colors for different heights or layers of heights like on the picture below.

I was just thinking in terms of generating the basic layers of colors for the topography without the houses, trees objects and units. I wasn't thinking in terms of creating a graphics engine that would solve this, but a simple way to generate a flat image on the screen.

The question is two-fold:

1, What kind of data could be used for this sort of generation? I was thinking maybe ASCII art which is kind of easy to create and modify to quickly change the topography, but would be difficult to provide height information.

2, What existing frameworks, classes, methods or methodologies could be used for solving the generation after having the data ready.

Godus: like this one

ASCII art (northern europe with ! for Norway, # for Sweden, $ for Finland and % for Russia: enter image description here

(Taken from the MapBox docs: http://mapbox.com/developers/utfgrid/#map_data_as_ascii_art)

like image 231
Zoltán Matók Avatar asked Dec 23 '12 13:12

Zoltán Matók


1 Answers

If you want to create a simple 2D, contoured image, I would try the following:

  • Create some height data. I'd just use a grey-scale image for that, rather than ascii. You can author basic height-maps in MS Paint, or anything similar.
  • Smooth the data. For example, apply a blur, or increase the resolution using a smooth filter.
  • Consider clamping all height data below a certain point - this represents a water level, if you want that.
  • Quantise the data. The more you quantise, the fewer but more obvious the contours.
  • Apply a false colouring, via a palette lookup. For example a : low lying areas blue, for water, then yellow, for sand, green for grass, brown for earth, grey for rock, and white for snow.

The important parts are the enlarging/smoothing filter, which creates more interesting shapes to your contours, and the quantisation which actually creates the contours themselves.

You can play with the stages of this. For example you could introduce some noise to the terrain, to make it look more natural if your source data is very clean. Or you could increase the smoothing if you want everything very rounded.

If you want to use ascii, you could just generate a bitmap directly from that, which wouldn't be tricky. The ascii you use as an example though is split up by country rather than terrain, so the false-colouring and contouring would probably do the wrong thing. You could probably use it as input to a simple terrain generator, perhaps just having a couple of chars to denote where you want land, sea, mountains, etc.

Here's a very basic example I knocked up, it's just an application of the technique I suggested. I didn't use any frameworks or libs, just a few simple image processing functions, and an height-map of Europe I found:

enter image description here

like image 65
JasonD Avatar answered Oct 13 '22 01:10

JasonD