What is this?
A 2D map is being generated that can later be converted to a 3D space for use as a level in a game. Using cellular automata, 2 bytes are used to generate 65,025 maps. The maps are not necessarily unique (different seeds and rules can result in the same map), but are perfectly repeatable. White space on the maps is empty and represents where the player can move, grey space is filled and shows empty areas that were non-contiguous with the player starting point.
What is happening here?
A random seed is converted to binary and expanded to fill the first line of an array*.
An elementary cellular automata is run using a random rule to fill the rest of the array.
To ensure the player has a space to start in every map, an 8x8 area is created in the middle.
The array data is then smoothed using another cellular automata that checks for crowding/loneliness. The smoothing automata is run several times, the number of times it is run depends on the inital array filling rule, to give different areas more or less smoothing.
Finally, a simple flood fill is started in the center of the landing pad to separate out the contiguous area where the player can move.
*Expansion of seed is done by filling eight cells of the array for every bit in the random seed. If the seed bit is "0" then the eight cells are left empty. If the seed bit is "1" the eight cells are filled with the bits of the seed.