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:

000 = 0
001 = 1
010 = 1
011 = 1
100 = 1
101 = 0
110 = 0
111 = 0
*The rule 0001 1110 is equivalent to 30 in decimal, hence rule 30.

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

[epoch 0]    0    0    1    0    0
[epoch 1] 0
[epoch 0] 0 0 1 0 0
[epoch 1] 0 1
[epoch 0] 0 0 1 0 0
[epoch 1] 0 1 1
[epoch 0] 0 0 1 0 0
[epoch 1] 0 1 1 1
[epoch 0] 0 0 1 0 0
[epoch 1] 0 1 1 1 0
*The code assumes 0 on the edge cases.

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.

function rules (i)
local ruleset = {
{0, 0, 0, 1, 1, 1, 1, 0}, -- Rule 30
{0, 0, 1, 0, 1, 1, 0, 1}, -- Rule 45
{0, 1, 0, 1, 1, 0, 1, 0}, -- Rule 90
{0, 1, 1, 0, 1, 1, 1, 0}, -- rule 110
{1, 0, 1, 1, 0, 1, 1, 0}, -- rule 182
{1, 0, 1, 1, 1, 1, 1, 0}, -- rule 190
{1, 1, 0, 1, 1, 1, 1, 0}, -- rule 222
}
...

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.

--

--

--

https://github.com/booletic

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to re-execute failed nodes automatically in KNIME

Key Phases In Creating A Website

Where am I supposed to start with GitHub?

Any Way To Export WooCommerce Orders And Products (2020)

BGP — Always Compare MED

Forging Your Telegram Bot

The Definitive Guide for setting up a clean and working AWS EKS Kubernetes Infrastructure

EKS Cloud Infrastructure

very strong project, thanks for the opportunity to get in early

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mansoor Aldosari

Mansoor Aldosari

https://github.com/booletic

More from Medium

You are being surveilled, e-privacy does no exist

Rick’s Suicide Attempt

Researchers warn of unpatched DogWalk Microsoft Windows vulnerability.

View from the arXiv: Feb 14 — Feb 18 2022 | Dr S J Thomson