# Applying voronoi to a 2D tile map

I'm planning to use Voronoi cells to break up an infinite 2D (procedurally-generated) tile map into biomes. I've been reading a bunch of tutorials and introductions to voronoi, and I understand how cells are calculated based on points, but I'm failing to understand how to apply this to an infinite 2D tile map.

1. Voronoi cells are calculated from a series of points, but given a 2D tile map, how do I consistently generate a list of points? I can randomly choose points but this has to be completely reproducible with the given RNG seed.

2. How can I calculate cells for an infinite map when every Voronoi implementation I can find requires a bounding rectangle?

• Can you please confirm that your map is "infinite" because it tiles, so every thing repeats once you reach one of the border of the map? Mar 10, 2017 at 7:31
• I'm not sure I've understood your problem, but do you want your Voronoi cells to be tiled in the same pattern as your map, or the cells should be unrelated to the map tiling? Apr 24, 2017 at 11:59

Break up the world into chunks or larger areas. They should have a uniform size, they should store their positions with a short, and each of them should contain some points.

Let's convert it to a seed to give to the random function. Every variable has a minimum value, for signed types this is negative. For example the minimum value of an integer is -32768. If you add this to the coordinates of the chunk, you'll always get a positive value.

You'll now have 2 coordinates, one on the x axis and one on the y axis, and both of them are positive.

You can concatenate this into an int by doing some bitwise operations:

x << 16 & y


This is your seed. This'll be unique for every chunk. Now you can set Random.seed to this and get the same results every time.

When you generate your biomes in a chunk, you need to generate the points in the chunks next to the current one, and use the resulted points to calculate the biomes in the current chunk.

I'll leave it to you how you generate your points, but a possible solution would be to first generate how many points there are in that area, then generate the position of the points and the type of the point (what chunk it resembles).

The only problem with this is that it only allows you to have 65536 chunk in each direction. You can solve this by using ints and you concatenate them into a long, but I haven't found a way yet to use a long as a seed.