Cellular-Automata

This is a framework for running cellular automata built in python.

A Cellular Automata is a (typically infinite) grid of cells. Each cell has a state from a set of possible states. Once initialized, the cellular automata iterates, with the next state of each cell at each iteration being determined by a set of rules, typically based on the current state of the cell and the cells around it.

This should work with any simple (two dimensional, values of 1 or 0) cellular automata. The script allows you to pass an outside function in to the cellular automata to be used when iterating. This is useful for creating/testing many different cellular automata. The function need only accept x and y coordinates, as well as the current cellular automata object, and return the next state for that cell.

The following files are included:

  1. cellular_automata_framework.py - This is the cellular automata class. Create a new cellular automata by creating a new instance of this class. Call the iterate function to iterate it.
  2. cellularAutomata_Functions.py - This is a collection of rule set functions that I created, as well as the most famous rule set, Conway's Game of Life.
  3. cellularAutomata_Driver.py - This is a script I created for running and testing different cellular automata. In the script are functions for creating initial boars for the automata, saving the board to a text file, saving the board and related information to a JSON file, displaying the board, and taking a screenshot of the display.

CellularAutomata_driver.py utilizes my noise_squirrel5 package which can be found here: https://github.com/FiniteUI/Squirrel-Noise-5

I initially was playing around with them as a way to procedurally generate terrain for video games, and tested out over 200 functions. Most of the functions I tested were created randomly with by looking at different possibilites for a few different parameters. It is very difficult to tell how the automata will actually act from the ruleset, so I followed the mindset of creating a ton of them without much thought and seeing how they played out. Below are some of the more interesting results. The functions for these are the titles displayed at the top of the grid, and can be found in the cellularAutomata_functions.py script:

This function generates a maze like structure:

conway_modified_3_4137997834_2022-12-22-01-26-05

These functions generate splotchy, discrete masses. These could be useful for terrain generation for forests, rocks, hills, water, etc.:

conway_modified_11_1190056815_2022-12-22-11-40-57 conway_modified_12_4137997834_2022-12-22-01-27-10 conway_modified_13_4137997834_2022-12-22-01-27-23 conway_modified_14_1190056815_2022-12-22-11-41-45 conway_modified_15_4137997834_2022-12-22-01-27-57 custom_34_4137997834_2022-12-22-01-35-18 custom_192_3861191076_2022-12-22-19-08-49 custom_174_3809185859_2022-12-22-16-58-51 custom_191_2536668112_2022-12-22-17-02-19

These functions generates paths:

custom_48_1190056815_2022-12-22-11-55-05 custom_49_1190056815_2022-12-22-11-55-37 custom_52_1190056815_2022-12-22-11-57-17 custom_55_1190056815_2022-12-22-11-58-12 custom_71_1190056815_2022-12-22-12-00-54 custom_36_4137997834_2022-12-22-01-35-49 custom_37_1190056815_2022-12-22-11-50-47 custom_38_4137997834_2022-12-22-01-36-57 custom_44_1190056815_2022-12-22-11-53-03

These functions generate large blocky areas:

custom_46_1190056815_2022-12-22-11-54-28 custom_51_1190056815_2022-12-22-11-56-43 custom_45_1190056815_2022-12-22-11-53-45

These functions generate competing sections of vertical and horizontal lines:

custom_81_1190056815_2022-12-22-12-01-52 custom_89_1190056815_2022-12-22-12-03-01 custom_216_114828706_2022-12-22-21-53-39 custom_217_114828706_2022-12-22-21-54-28 custom_221_114828706_2022-12-22-21-55-43

These functions generate piles of "snakes":

custom_202_1435913884_2022-12-22-21-24-38 custom_203_1435913884_2022-12-22-21-25-19 custom_204_3537409248_2022-12-22-19-11-35

This function generates some discrete areas with a distinct pattern:

custom_220_114828706_2022-12-22-21-55-06

These functions devolve into small cycling blocks:

custom_225_549904416_2022-12-22-22-03-36

And here's a few more slightly less interesting ones for good measure:

custom_171_3442291744_2022-12-22-14-40-28 custom_229_13505776_2022-12-22-22-05-51 fourDirections_threeOrMore_1190056815_2022-12-22-11-38-48 custom_10_1190056815_2022-12-22-11-46-45 custom_165_3442291744_2022-12-22-14-36-46 custom_207_1435913884_2022-12-22-21-27-33 custom_208_1513686562_2022-12-22-21-47-22 custom_73_1190056815_2022-12-22-12-01-05 custom_75_1190056815_2022-12-22-12-01-09 custom_65_1190056815_2022-12-22-11-59-06 custom_53_1190056815_2022-12-22-11-57-28

Apart from these, many of them end up in uninteresting cycles or blank voids of black or white. However, while some of them don't produce interesting end points, many of them actually display interesting movement patters that the screenshots/endpoints don't reflect. Also, I am using a 100 by 100 grid, running them for 100 iterations, and giving completely randomized input. It is very possible that changes in grid size could produce different results. It's also possible that different types of input (different densities, patterns, etc) could produce different results. Lastly, while some of them terminate in empty grids or simple cycles, they may show interesting patters earlier in their iterations. Ones that do not terminate but don't show interesting results, may show better results if ran for more iterations.

I will be working on more in the future, utilizing new parameters and different combinations of existing parameters.