Cellular Automata

Cellular Automata

Cellular automata are a class of models used to simulate complex systems. They are used in a wide range of applications, including modeling the spread of diseases, traffic flow, and crowd behavior. This project is a one-dimensional cellular automata.

Cellular Automata Details

We start with an initial row. In this app, the row is a series of white squares followed by a single black square and more white squares.

A cell is created based on the state of the three cells above it (directly above and to the left and right). That means there are eight possible combinations of the three cells. We consider a white square to be a 0 and a black square to be a 1. This gives us a number between 0 and 7 (the cell update number).

The rule is a number between 0 and 255 (inclusive). We take that number and convert it to its binary representation, which will be a sequence of 8x 0s and 1s. We look at the corresponding digit in the rule by taking the cell update number. If it is a 1, the cell becomes black; if it is a 0, the cell becomes white.

The cellular automata is visualized as a grid of white and black boxes, representing the 0 and 1 states, respectively.

User Interface

The app provides three main inputs:

Key Technologies and Techniques

Server-Side Logic

The app uses FastHTML to define routes and handle the cellular automata logic on the server. Key routes include:

State Management

The automata state is managed server-side using a generator function:

Dynamic Content

HTMX is used extensively to create a dynamic user interface: