# Cellular automata – Langton’s Ant

Visualization of a simple algorithms of two-dimensional Turing machine can create impressive images. The “movement” of the head of Turing machine can be irregular in the early stage, but it start making characteristic patterns after millions of iterations. In this post I will show how to define a table of rules the Turing machine for a simple cellular automaton that isÂ Langton’s antÂ and sample visualizations of the work of other machines.

## Turing machine model and image processing

The Turing machine modelÂ is used to perform algorithms. We can define the following attributes of this model:

- Set of states – possible states that can adopted by the head
- Set of input symbols
- Set of outputs symbols
- Initial state

In the process of image processing by a Turing machine, the tapeÂ will be a bitmap. The machine based on the state of the head and a value of the pixel at the current position, set the output value of the pixel accordance with a defined rule, update state of the head and move it to the desired location in space. To reduce the size of the input alphabet, you can use a modulo operation on the RGB value of a pixel.

### Lanton’s ant

Lanton’s ant is a simple cellular automaton. It moves in an infinite grid divided into square fields. I will show how you can define the rules table of the two-dimensional model of a Turing machine for this.

#### Rules

**if ant is located at a black field:**- change color of field to white
- turn right and move forward one unit

**if ant is located at a white field:**- change color of field to black
- turn left and move forward one unit

As you can see, the ant flips the current color to the opposite and moves only orthogonally. This rule is very easy to transform to the model of the Turing machine.

#### Langton’s ant – table of rules

State | Î² | Î´ | Ïƒ | |||
---|---|---|---|---|---|---|

0 | 1 | 0 | 1 | 0 | 1 | |

0 | 3 | 1 | 1 | 0 | 3 | 4 |

1 | 0 | 2 | 1 | 0 | 2 | 5 |

2 | 1 | 3 | 1 | 0 | 4 | 3 |

3 | 2 | 0 | 1 | 0 | 5 | 2 |

- State: current state of the head
- Î²: output state of the head
- Î´: output value of the field
- Ïƒ: output position of the head

The value of each attribute model, depends on the value of field at the current position of the head. We have to define rules for each symbol from the input alphabet. The value of attributeÂ ÏƒÂ is related to the index of fields defined in the neighborhood model.

#### Neighborhood

The ant can move only two possible positions, which are located next to it. Excluding the angle of the ant, it can move in four different directions. The following figure presents a two-dimensional model of the neighborhood used in the Langton’s ant rule and in the other visualizations in the gallery.

#### Visualizations

## Gallery of Turing machines

In this section I will present gallery of the work of Turing machines with different rules. Images come from my own program to visualize the work of Turing machines.

### “Magic” square – bitmap processing

### Figures – bitmap processing

### Letter “E”

### Labyrinths

### Highways

### Triangles

### Blocks

## Summary

Very simple rule after hundreds of thousands or millions of iterations of chaotic movements can create amazing patterns and shapes. Presented visualizations are part of the possible combinations. If you know other an interesting rule –Â send me a message.

## Comments