Procedural Island Generator

I made a little Windows app to test out some code for randomly generating simple islands to be used as the basis for a tile map in a 2D game. Essentially it’s just recolouring some fractal noise generated with a standard midpoint displacement algorithm with a few added tweaks.

Download: islands.zip

In this instance a 128×128 array is seeded with a random value every 16 rows and colums then each 16×16 square is filled in using the midpoint displacement method.

Seeding the border with zeroes before filling in the 16×16 squares guarantees that the result is always an island completely surrounded by water.

Setting the central point to the maximum value makes the generated islands a little more consistent. To ensure that every part of the generated terrain is accessible to the player I remove any isolated sections by performing a simple flood fill from the center in order to identify any disconnected points above the water level.

Finally a boundary of shallow water is added around the coastline to make things look a bit nicer.

7 thoughts on “Procedural Island Generator

  1. HamHam

    Hey, I’m having difficulty understanding this example. From what I understand about the midpoint displacement , on the edges, it should have seeded values in the around the edges during the first iteration. However, if you divide a 128×128 grid into 16×16 squares, and place seeded values in the top left of the square, there is going to be a 15 point buffer at the end right side and the end bottom side, and no seeded values on the right side and the bottom.

    Can you clarify how you did that part?

    Thanks!

    1. Chris B Post author

      It wraps around – for the bottom-right point it’s actually using the top-left point. So if I don’t zero the borders to make islands I get a seamlessly tiling pattern.

    1. Chris B Post author

      I can dig out the PureBasic source and mail it to you. It’s kind of messy and poorly commented, but maybe it’ll be of some use?

      1. TheEnigmist

        I was trying to make the same generation in C#, but i didn’t get anything good. I want to generate big islands and this is can be a good starting point :) Nevermind if its poorly commented, i will try to understand it :) Thx

        1. Chris B Post author

          Well the way I’ve implemented my midpoint displacement stuff – ie. by seeding the map with a grid of random values then setting the central point to the maximum value – increases the likelihood of a bigger island being generated, but it doesn’t guarantee it.

          However, by counting how many pixels I’ve filled during the flood-fill stage, I can return the number of pixels from my generation function then just repeat it until it exceeds a required size.

Comments are closed.