I'd like to generate flat islands existing of multiple hexagons. So far I've been able to create hexagonal meshes with code, but can't figure out how to position them in groups, creating a randomly shaped island. (Any shape that's not a perfect circle, square etc.) I think I would need an algorithm, that places hexagon tiles next to multiple sides of an existing tile. If you can help me with an idea for an algorithm, then that would be great.
-
You've asked a very wide-ranging question (there are lots of ways of generating patterns of hexagons!), without a well-specified goal (what kind of island shape is acceptable?). You've also given two exceptional cases (half hexagons and a "fall off edge") without explaining how you think they would work. That means this is an extremely broad question - so answers are unlikely to be able to cover everything - and it's not clear whether you're looking for help with algorithm or code or something else. I'd suggest you break the problem down more yourself, and then ask a more specific question. – Dan Puzey Jan 19 '16 at 00:22
-
@DanPuzey I'm sorry Dan, I didn't realize it was that bad of a question. It's really not that complicated as you make it sound though.. The shape I'm looking for is anything that doesn't look artificial. So no perfect circle, square, line or triangle. To keep it simple I'll drop off the smoothening tiles. (Which are just different shapes to make the island not look too much like a grid) and the fall off edge, which are walls at the edge of the island that go downwards. Any help is appreciated, wether it is just an idea for an algorithm, or actual code. I'll edit my question. Thanks – user2255273 Jan 19 '16 at 00:34
-
Is there anything you've tried so far to solve your problem? And how are you generating your hexagonal grid? So far your question appears to be asking people to write the next part of your code without being able to see what the first part is yet; that's not likely to result in an answer that's useful to you (or to future readers!). – Dan Puzey Jan 19 '16 at 00:54
-
Come on Dan, I've clearly stated that I'm just looking to see if someone can steer me in the right direction. I need no code, just a hint from someone who has done this before. I've been breaking my head over this for the past few days trying out voronoi diagrams and delaunay triangulation. Honestly don't get why you are being this hard on me.. – user2255273 Jan 19 '16 at 00:59
3 Answers
Are you looking for something like this?
Place 1 hexagon.
for i in (islandSize-1):
Scan all hexagons for open sides. Place open sides in a list named hexBorders
Choose a random index in hexBorders, attach a new hexagon there
That algorithm should give you a fairly roundish island, roughly centered on the original hex, because older hexes have more chances to get picked.
You can tune this shape by preferring either newer or older hexagons (e.g. you could include hexagon age in hexBorders, and adjust your random choice so it prefers younger hexes).

- 5,329
- 2
- 29
- 34
-
Thank you Luke, I had not thought about checking all hexagons for open sides every time one is placed. I only thought about just checking the newly placed hexagons for open sides, which would result in too much of a line. I'm going to try this. Thanks again! – user2255273 Jan 19 '16 at 01:14
Recently I was also doing random map generator for tile based map and hit a wall while try to add more advanced features (in tile space) the realism of output was not good. I decided to create a 2D/3D image based map and then convert it to tile map. Still not finished with adding all the features I want but the result is already a magnitude better then before:
map generator
see my simple random map generator in C++. It is based on Diamond&Square algorithm with some tweaking to obtain island like maps.
conversion to tile-map
Simply map Cartesian pixel into your hexagonal grid layout. You can also compute the average of some area instead of using single pixel per cell/tile.
For 3D tile maps this will produce "voxel-ated" output so you need to add additional filtering see
- How to procedurally generate tile map for some ideas.
Since is a pretty open ended question, this article by Red Blob Games about hexagonal data structures would be an excellent place to start. The author describes how you can use 2D arrays to store the hexagons, and how you can iterate through them.
Once you understand the relation of hexagons to one another you can start to iterate through them in interesting ways.
Probably the easiest way to generate an "island" would be with a SIR-type model, also known as an epidemic model. This is a model that is commonly used by researchers to simulate the spread of infectious disease, but I've found that you can also use it to generate pseudo-natural shapes (like an island!). SIR stands for Susceptible-Infectious-Recovered. Those are the three states of a "cell", or in this case hexagon. At any given step of the algorithm, an infected cell can infect a neighboring cell. Think about it like this: at the start of your algorithm, one hexagon is "infected" (land) and the rest are not (water). At each iteration of the algorithm, cells adjacent to an infected cell have a chance (say, 1 in 10) of being infected as well (turning into land). After many iterations, you'll find that the shape of the infected group of hexagons is pretty random looking, but they're all touching. For a grid-bsed example, here's some images I've uploaded to imgur. Pseudo-code for this algorithm is below.
cellsToDo = [originCell]
for 100 iterations:
for each cell in cellsToDo:
for each neighbor to the current cell:
if randomValueBetween(0, 10) == 1:
set the current cell as infected
add the current cell to the cellsToDo list
There are definitely other algorithms, but I'd start with learning how the hexagons are related to each other and can be stored.

- 442
- 2
- 8