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

后端 未结 1 881
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 13:30

So upon seeing images from Godus I was wondering how to generate a simple, non-interactive, 2D image with different colors for differe

1条回答
  •  再見小時候
    2021-02-04 14:02

    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

    0 讨论(0)
提交回复
热议问题