日本語
Dark

Langton's Ant

This is a website where you can play with Langton's Ant in your browser. Various extended versions are available to try.
This is my first time creating a site like this, so there may be some inconveniences. Any feedback, no matter how small, in the comments section below would be greatly appreciated.
Also, since I am Japanese, my English may be unnatural in some ways.
Sorry, the image is not in English yet because I have to replace it.

What is Langton's Ant?

Langton's Ant is a type of cellular automaton, a simulation where a virtual "ant" moves based on simple rules.
In short, it's a simulation where an ant moves on a grid of black and white squares, flipping their colors according to a rule. Here, the ant is represented by a red triangle.
It was created by Christopher Langton*¹, and it's said to have gotten its name because the way the squares are flipped resembles a moving ant.

  1. If the ant is on a black square, it turns left 90 degrees. If it's on a white square, it turns right 90 degrees.
  2. It flips the color of the square it was on.
  3. It moves forward one square.

The ant repeats these three rules in order. Starting from an initial configuration*² where all squares are white, the ant's movement initially appears chaotic, but after about 10,000 steps, it begins to build a "highway." It has been experimentally shown that it creates a highway from any initial configuration.

Rule explanation


*1 Christopher Langton (1949-?) is an American computer scientist and a pioneer in artificial life research.
*2 The initial configuration refers to the state (black or white) of the squares. However, the number of either white or black squares must be finite.

Mode Selection

You can play with Langton's Ant using the buttons below. If you are on a smartphone or tablet, please press the "Mobile Version" button before selecting a mode.
Instructions and explanations are provided below. If you don't understand the rules, I recommend starting with the Normal Mode.
The Pattern Gallery is a place where various ant trail patterns are recorded. There are many interesting trails, so please take a look.

How to Play

Click on each mode's button to display its instructions.
Press the tutorial button on the right to jump to the tutorial, which explains how to use the site and provides an overview of Langton's Ant.

Normal Mode

You can watch the standard Langton's Ant in action. You can play by changing the initial configuration or adding more ants.
The red triangle is the ant. The instructions button will show you controls almost identical to the ones listed below.

Try drawing a picture and letting the ant move. It should build a highway no matter what you draw.

Conditional Mode

The basic controls are the same as in Normal Mode. You can add a condition: "every n steps, move forward k steps without turning."
Additionally, you can change the number of steps taken when turning left or right.

Try out various combinations. There are many interesting patterns, including some that build a highway from the start. Setting n=0 results in normal behavior.

Four-Way Mode

In this mode, the direction of movement is determined by the combination of colors of the "previous square" and the "current square."
There are 4 combinations of black and white, and 4 directions (up, down, left, right) for each, resulting in 256 possible rule sets. The first step is treated as if the previous square was white.

This mode often produces more orderly patterns, such as expanding spirals. A Left-Right-Left-Right rule set will replicate the Normal Mode.

Multicolor Mode

This mode uses more colors. The ant follows the rule for the color of the square it's on: turn left or right, change the square's color to the next one in the sequence, and then move forward.
The color sequence is: White → Black → Red → Blue → Green → Yellow → Purple → Orange → Cyan → Pink → Brown → Gray. A maximum of 12 colors can be used.
For example, with 3 colors and a rule of Left-Right-Left, if the ant is on a red square, it will turn left, change the color to white, and move forward.

If you use an even number of colors and an alternating Left-Right rule, it will behave like the Normal Mode.

State Mode

The ant itself has multiple states, and its behavior changes depending on its current state.
For example, the default rule set has two states (0 and 1):
In state 0, if on a white square, it moves forward 1 step without turning or inverting the color, and changes to state 1.
      If on a black square, it inverts the color, turns right, moves forward 1 step, and changes to state 1.
In state 1, if on a white square, it inverts the color, turns left, moves forward 1 step, and changes to state 0.
      If on a black square, it inverts the color, moves forward without turning, and stays in state 1.

If you set color inversion to 'Yes' for all states and set the direction to 'Right' for white and 'Left' for black, it will behave like the Normal Mode.

Hexagonal Mode

This mode uses a hexagonal grid. Normally, if the ant is on a black hex, it turns 60° left and moves forward; if on a white hex, it turns 60° right and moves forward. The controls are the same as in Normal Mode.
In Multi-Color mode, the rules are the same as the standard Multi-Color mode, but with six possible directions: Up-Right, Down-Right, Down, Down-Left, Up-Left, Up.
In Conditional mode, the rules are the same as the standard Conditional mode: every n steps, it moves forward k steps without turning.

Collatz Mode

In this mode, the ant's movement is based on the Collatz conjecture. The Collatz conjecture is:

  1. Pick any positive integer.
  2. If the number is even, divide it by 2. If it's odd, multiply it by 3 and add 1.

The conjecture, which is an unsolved problem in mathematics, states that repeating step 2 will eventually lead to the number 1 for any starting integer. After reaching 1, the sequence enters a cycle: 1 → 4 → 2 → 1 → 4 → 2...

This is similar to Langton's Ant in that it seems to always converge and form a cycle from any initial state (initial value), which is experimentally observed but not mathematically proven.

In this mode, the ant moves according to the operations on the initial value. You can also modify the rules, for example, dividing by 4 if even.

The default setting is: if n is even, divide n by 2, invert the square's color, and move right. If n is odd, multiply n by 3 and add 1, invert the color, and move left.

The simulation stops automatically when n reaches 1. Pressing the start button again will continue the movement. Note that if n is not divisible, the result will be truncated (floor division).

Currently, the square's color is not used for branching decisions, but I'd like to create something where the black/white color of the square also influences the path.

Frequently Asked Questions

About Langton's Ant

Q. You say it builds a highway after about 10,000 steps. How many steps exactly?
If the initial configuration is all white, it starts building the highway on the 9,978th step.
Q. The highway seems to extend by repeating the same movements. Does it have a period?
Yes, the highway has a period of 104. This means it repeats a sequence of 104 steps to build the highway.
Q. Is it only known experimentally that it builds a highway from any initial configuration?
Yes. It has not been mathematically proven that it will always build a highway.
Q. Is there an initial configuration where the ant starts building a highway from the very first step?
Yes, there is. With the configuration below, it starts building a highway immediately. This is the minimal set of squares from the 9,977th step required to build the highway.
Replication of the 9977th step
Q. Does the highway extend infinitely?
Yes. It has been proven that if an ant builds a highway, that highway will extend infinitely. However, it has not been proven that an ant will build a highway from any initial configuration.
Q. What can be learned from studying Langton's Ant?
It demonstrates how simple rules can lead to chaotic behavior that eventually gives rise to order, allowing us to study mechanisms similar to pattern formation in nature. Its ability to create complex patterns also lends it to artistic applications.

About This Site

Q. What was used to program each mode?
Everything was programmed using JavaScript.
Q. In Normal Mode, what happens when multiple ants are on the same square?
They move in the order Ant 1 (Red) → Ant 2 (Blue) → Ant 3 (Green). For example, if Ant 1 and 2 are facing up on the same white square, Ant 1 will turn it black and move right, then Ant 2 will turn it back to white and move left. As a result, the square's color doesn't change.
Q. How can I make multiple ants face different directions?
Ants 2 and 3 always face up when added. So, change the direction of Ant 1 first, and then add the other ants to have them face different directions.
Q. Is it possible to have a mode that combines Conditional, Multi-Color, and State rules?
That would be quite difficult due to various conflicts. I might add it someday.
Q. How did you determine the period and the number of steps before the highway forms?
I represented the ant's direction (Up, Right, Down, Left) as 0, 1, 2, 3 respectively, and recorded the sequence of numbers as the ant moved. I found the repeating sequence of 104 steps (the period) and then located the point where this periodicity breaks (just before the highway).
Q. How are submitted comments handled?
They are displayed in the comment history below. If you check "Submit Privately," the comment will only be visible to the creator.

References

mini-ant

Comments

Feel free to post your thoughts, questions, or anything you've noticed. I will make corrections as needed based on suggestions for improvement or areas that need more explanation.
If you check "Submit Privately," your comment will be sent only to the creator and will not appear in the history below.

Thank you!

History

Loading...

Creator Information

Update History

Show More




mini-ant