Cellular Automata meet Love2D

The following is an implementation of cellular automata using Love2D (an engine for game development).

So, what is Cellular Automata?

A cellular automaton is a collection of “colored” cells on a grid of specified shape that evolves through a number of discrete time steps according to a set of rules based on the states of neighboring cells. The rules are then applied iteratively for as many time steps as desired. — wolfram.com

Conway’s Game of life is the most popular 2D cellular automata. However, this example is an implementation of 1D cellular automation. Below is the outcome of rule 30 (there are many rules embedded in the code):

Game of life by Conway is one of the most famous 2D cellular automata. However, this example is an implementation of 1D cellular automation. Below is the outcome of rule 30 (there are many rules embedded in the code).

This case represents a stack of rows that represents epochs. Each row is an array of cells (black or white), and epochs start from top to bottom. The first row has one black cell. The next row is the result of the previous row and a rule.

Each cell is determined by looking at the neighboring cells from the last epoch. Let’s assume that the length of each row is 5 for simplicity and the rule:

Now, we set the first epoch to 00100, and the result is 01110.

If we keep applying this simple rule on every row, a very complex behavior will emerge, resulting in the generation of the pattern displayed in the screenshot above!

As you can see, simple rules will evolve into unpredictable patterns. The complete code is linked below, and since the code follows a data-driven approach, you can easily add your rule-set.

It’s a new kind of science. I still remember the excitement I got from realizing the paradigm shift of algorithms generated by algorithms (neural networks). Now cellular automata give me the same vibes, I’m not sure what it will evolve to, but I believe it will be something beautiful.

This story was influenced by Stephen Wolfram, many thanks to him.

Programming and Statistics for now!

More from Mansoor Aldosari

Programming and Statistics for now!