In this article I will write a simple implementation of a 1-dimensional cellular automaton in JavaScript.

The concept of cellular automata has existed since the middle of the 20th century and has grown into a vast field with many practical and theoretical applications.

A cellular automaton consists of any number of “cells” arranged in 1, 2, 3 or more dimensions. Each has a state associated with it (in the simplest case just on or off) and each cell and therefore the entire automaton transitions from one state to the next over time according to a rule or set of rules.

The number of dimensions, the number of possible cell states, and the rules can become arbitrarily large and complex but for this project I will implement the simplest type of one-dimensional cellular automaton, known as an elementary cellular automaton.

The Elementary Cellular Automaton
An elementary cellular automaton consists of a row of cells, each of which can be “on” or “off”, illustrated in the table below with 0s and 1s.

Image for post

For the purposes of calculating the next state of each cell, individual cells are considered to have a “neighbourhood” consisting of the cell itself and the two cells either side. For the cells at the ends one part of the neighbourhood is the cell at the other end, so the automaton can be considered to be logically circular. The next table shows the neighbourhoods of the two cells shown in bold.

Image for post

There are 8 possible neighbourhoods and therefore the rules for setting the next cell state can be represented by a byte. The decimal values 0–255 represented by all possible bytes form what is known as the Wolfram Code after Stephen Wolfram who carried out research in the area and wrote the book A New Kind of Science.

Here is the Wolfram Code for Rule 30, the bits of the second row forming 30 in binary

Image for post

A 1D cellular automaton’s states over time are usually represented by consecutive rows with the states represented by blocks of different colour. In this project I will write an HTML/JavaScript based implementation, and this is a screenshot of a sample run using Rule 109. Some patterns produced can be much more interesting than others.

#programming #web-development #software-development #cellular-automata #javascript

One-Dimensional Cellular Automaton in JavaScript
2.70 GEEK