December 23rd, 2012Langton's Ant
Basically, it is just a grid with each cell having a state. An ant then moves around on the grid. Before each move, the ant increments the current cell's state and changes its own moving direction according to the current state.
The exact behaviour is described using a string of letters R (right) and L (left). I also added S (straight) and T (turn around), because they add a lot of possibilities.
In addition to the patterns on Wikipedia, I found these through experimentation:
This one draws a straight line and then fills the whole canvas in one color. Afterwards, chaos ensues. You can add more [i]S[/i] to the beginning, which makes the ant fill the canvas in different colors after each other.
This one also draws a straight line to begin with, but then produces quite a beautiful grid.
This one is great with more than one ant!
This is one of the few oscillators I found. It also shows how the ants can work together: Single ants just oscillate in a small radius around their spawn point. But if you put more ants together, they can build bridges and move around.
- Create new Ants
The script supports unlimited ants. Just click on the canvas to spawn a new one at the current mouse position. The default configuration is a single ant right in the middle of the canvas.
- Start/Stop and Step
Click Start/Stop to start or stop the simulation. Step executes exactly one generation.
The speed range is 1-30, modify the current speed by clicking + and - while the simulation is running.
Note: The effect of this setting may vary greatly between different browsers and systems. Chrome, for example, is much faster than Firefox.
- Set Mode and Restart
Here you can restart the simulation and set a new behaviour pattern for the ants. See above for the syntax. A maximum of 100 letters are allowed, letters other than R, L, S and T are ignored (case-insensitive).