Langton’s Ant was invented in 1986 by Chris Langton as a simple example of a cellular automaton. It’s a two-dimensional Turing machine that follows extremely simple rules: the “ant” turns right on a white square, left on a black square, and flips the square’s color as it moves. In this notebook, we explore its evolving patterns and experiment with variations of the rules to uncover intriguing animations.

Classic Langton Ant pattern

In[]:=
Manipulate[Module[{newlist,n,running,leftTurns,rightTurns,turnData},​​newlist=Nest[iterate,{{{0,0},{},0},{{0,1},{{0,0}},-(π/2)}},steps];​​leftTurns=0;​​rightTurns=0;​​Do[If[i>2,If[newlist[[i,3]]>newlist[[i-1,3]],leftTurns++,rightTurns++]],{i,2,Min[run,Length[newlist]]}];​​​​turnData=Table[Module[{lt=0,rt=0},Do[If[j>2,If[newlist[[j,3]]>newlist[[j-1,3]],lt++,rt++]],{j,2,i}];​​{i-1,lt,rt}],{i,2,Min[run,Length[newlist]]}];​​n=Max[Flatten[newlist]]+1.5;​​​​​​Grid[{{(*Antsimulation*)Graphics[{{Map[Rectangle[#-{.5,.5},#+{.5,.5}]&,newlist[[run,2]]]},{Rotate[Translate[{Red,ant},newlist[[run,1]]],newlist[[run,3]]]}},ImageSize->380,GridLines->{Range[-n,n,1],Range[-n,n,1]},PlotRange->n],(*Turntrackinggraph*)ListLinePlot[{Table[{turnData[[i,1]],turnData[[i,2]]},{i,Length[turnData]}],Table[{turnData[[i,1]],turnData[[i,3]]},{i,Length[turnData]}]},PlotLegends->{"Left Turns","Right Turns"},PlotLabel->Style["Turn Count Evolution",Bold],AxesLabel->{"Step","Count"},PlotStyle->{Blue,Orange},PlotMarkers->Automatic,ImageSize->350,GridLines->Automatic,PlotRange->All,Frame->True]},{(*Displaycurrentturncounts*)Panel[Row[{Style["Current Stats: ",Bold],"Step: ",run-1," | ",Style["Left Turns: ",Blue],leftTurns," | ",Style["Right Turns: ",Orange],rightTurns," | ","Ratio (L/R): ",If[rightTurns>0,NumberForm[N[leftTurns/rightTurns],{3,2}],"N/A"]}],FrameMargins->5],SpanFromLeft}},Alignment->Top]],{{run,1,"current step"},1,steps+2,1,Animator,AnimationRate->8,AnimationRunning->Dynamic[running],AppearanceElements->{"ProgressSlider","PlayPauseButton","StepLeftButton","StepRightButton","FasterSlowerButtons"}},{{steps,100,"max steps"},None},​​Row[{Spacer[{1,20}],"Max Steps: ",PopupMenu[Dynamic[steps,{(steps=#;run=1;running=False)&}],Join[Range[50,500,50],Range[600,1000,100],Range[1200,1500,150]]]," ",Button["Reset",(run=1;running=False)]," ",Button["Go to End",(run=steps+2;running=False)]}],Initialization:>{(*Antgraphic*)ant=Scale[Translate[{{Disk[{-4,0},2.3]},{Disk[{0,0},{3,1.5}]},{Disk[{4,0},{3,2}]},{Thickness[0.002],Line[{{0,0},{0,3}}]},{Thickness[0.002],Line[{{-1,0},{-1,3},{-2,4}}]},{Thickness[0.002],Line[{{1,0},{1,2},{2,4}}]},{Thickness[0.002],Line[{{0,0},{0,-3}}]},{Thickness[0.002],Line[{{-1,0},{-1,-3},{-2,-4}}]},{Thickness[0.002],Line[{{1,0},{1,-2},{2,-4}}]},{Polygon[{{6,1},{6,-1},{7.5,0}}]},{Thickness[0.002],Line[{{-4,0},{-7,-1}}]},{Thickness[0.002],Line[{{-4,0},{-7,1}}]}},{-.23,0}],0.06];​​​​​​iterate[list_]:=Which[(*Onblacksquare-turnleft*)MemberQ[list[[-2,2]],list[[-1,1]]],Return[Append[list,{list[[-1,1]]+Which[dir[{list[[-2,1]],list[[-1,1]]}]=={1,0},{0,1},dir[{list[[-2,1]],list[[-1,1]]}]=={-1,0},{0,-1},dir[{list[[-2,1]],list[[-1,1]]}]=={0,1},{-1,0},dir[{list[[-2,1]],list[[-1,1]]}]=={0,-1},{1,0}],DeleteCases[list[[-1,2]],list[[-1,1]]],list[[-1,3]]+π/2}]],(*Onwhitesquare-turnright*)!MemberQ[list[[-2,2]],list[[-1,1]]],Return[Append[list,{list[[-1,1]]+Which[dir[{list[[-2,1]],list[[-1,1]]}]=={1,0},{0,-1},dir[{list[[-2,1]],list[[-1,1]]}]=={-1,0},{0,1},dir[{list[[-2,1]],list[[-1,1]]}]=={0,1},{1,0},dir[{list[[-2,1]],list[[-1,1]]}]=={0,-1},{-1,0}],Append[list[[-1,2]],list[[-1,1]]],list[[-1,3]]-π/2}]]];​​(*Directionfunction*)dir[{x_,y_}]:=If[y-x=={0,1},Return[{0,1}],If[y-x=={1,0},Return[{1,0}],If[y-x=={0,-1},Return[{0,-1}],If[y-x=={-1,0},Return[{-1,0}],Return["Error"]]]]];},ContentSize->{800,450},Alignment->Center,ControlPlacement->Top,SaveDefinitions->True]
At the start of Langton' s Ant, because the grid is entirely white and the ant begins facing right, every step initially triggers a right turn, which creates the impression of a bias toward the right until previously visited black squares begin introducing left turns and generating the chaotic pattern .

“Highway” generated after thousands of steps

loc={0,0};(*Ant'scurrentlocation*)​​dir={0,1};(*Ant'scurrentdirection:{0,1}isNorth*)​​blackSquares={};(*Alisttokeeptrackofblacksquarecoordinates*)​​path={loc};(*Alisttostoretheorderedcoordinatesoftheant'spath*)​​​​(*Numberofstepsforthesimulation*)​​numSteps=13000;​​​​(*Mainlooptogeneratethepath*)​​Do[(*Checkiftheantisonablacksquare*)If[MemberQ[blackSquares,loc],(*---Onablacksquare:turnleftandfliptowhite---*)dir={-dir[[2]],dir[[1]]};(*Rotatesdirection90degreesleft*)blackSquares=DeleteCases[blackSquares,loc];(*Removesthesquarefromtheblacklist*),(*---Onawhitesquare:turnrightandfliptoblack---*)dir={dir[[2]],-dir[[1]]};(*Rotatesdirection90degreesright*)blackSquares=Append[blackSquares,loc];(*Addsthesquaretotheblacklist*)];​​(*Movetheantforwardonestepinthenewdirection*)loc=loc+dir;​​(*Recordthenewlocationinthepathhistory*)AppendTo[path,loc];,{numSteps}];​​​​​​(*Drawthegeneratedpathwithaclearblacklineonawhitebackground*)​​Graphics[{Black,Thick,Line[path]},Background->White,ImageSize->500]
Out[]=
A highway forms in Langton’s Ant because, after a long period of chaotic wandering, the ant eventually encounters a repetitive cycle of configurations that forces it into a stable loop of movements..The rules themselves don’t change—the ant just happens to fall into a self-reinforcing path that never breaks. This is very intriguing as the algorithm is thought to be unpredictable and totally unexpectable.

Two Ants

(*Ant1(Black)*)loc1={0,0};​​dir1={0,1};(*StartsfacingNorth*)​​path1={loc1};​​​​(*Ant2(Red)*)​​loc2={1,1};(*Startsatadifferentlocation*)​​dir2={0,-1};(*StartsfacingSouth*)​​path2={loc2};​​​​(*SharedGrid*)​​blackSquares={};(*Asinglelistofblacksquaresforbothants*)​​​​numSteps=14000;(*Increasedstepstoseemorecomplexinteractions*)​​​​(*---MainSimulationLoop---*)​​Do[(*CheckifAnt1isonablacksquare*)If[MemberQ[blackSquares,loc1],(*Onblack:turnleft,fliptowhite*)dir1={-dir1[[2]],dir1[[1]]};​​blackSquares=DeleteCases[blackSquares,loc1];,(*Onwhite:turnright,fliptoblack*)dir1={dir1[[2]],-dir1[[1]]};​​blackSquares=Append[blackSquares,loc1];];​​(*MoveAnt1forwardandrecorditspath*)loc1=loc1+dir1;​​AppendTo[path1,loc1];​​(*CheckifAnt2isonablacksquare*)If[MemberQ[blackSquares,loc2],(*Onblack:turnleft,fliptowhite*)dir2={-dir2[[2]],dir2[[1]]};​​blackSquares=DeleteCases[blackSquares,loc2];,(*Onwhite:turnright,fliptoblack*)dir2={dir2[[2]],-dir2[[1]]};​​blackSquares=Append[blackSquares,loc2];];​​(*MoveAnt2forwardandrecorditspath*)loc2=loc2+dir2;​​AppendTo[path2,loc2];,{numSteps}];​​​​Graphics[{{Black,Thick,Line[path1]},(*Ant1'spath*){Red,Thick,Line[path2]}(*Ant2'spath*)},Background->White,ImageSize->600]
Since one ant starts facing north and the other south, their movements are mirror opposites from the beginning. At first, their trails interfere with each other, producing lots of chaotic, tangled paths as they keep flipping each other’s squares. But over time, just like a single ant, each one eventually falls into a stable repeating cycle — the “highway.” Because of the initial symmetry, their highways end up being mirror images: one drifting off toward the top-left, the other toward the bottom-right.

Hexagonal grid

We see that it creates some interesting honeycomb patterns,the ant does not seem to form a highway at all, but instead does drift into symmetric, repeating hexagonal structures

Constructor

This rule structure builds a spiral-like animation because the state transitions alternate between turning (L/R/U) and forward/neutral moves (N/S), which continuously shifts the ant’s heading while preventing long straight runs. As a result, the ant keeps curving around its own path, resulting and finishing into a self-reinforcing loop that manifests as a spiral.

SnowFlake

By changing the rules of the ant’s growth , we see that the new rule produces a snowflake pattern because it combines sharp turns (L/R/U) with state-dependent branching, forcing the ant to repeatedly reverse or rotate sharply while painting new cells. These repeated rotations and mirrored state transitions generate radial symmetry, causing the paths to grow outward in multiple arms like a snowflake.

Archimedean spiral

This rule now forms an Archimedean spiral because the ant’s movement alternates systematically between left and right turns depending on the color of the cell, while the sequence of 11 colors gradually rotates its heading. Each turn slightly offsets the direction from the previous, causing the ant to move outward in a consistent, expanding curve, which produces the characteristic evenly spaced spiral of an Archimedean pattern.
​

Other cool animations

This project was inspired by
https://evolvecode.io/turmites/index.html​
​
​https://youtu.be/7x9J7rsLC50​
​
​https://demonstrations.wolfram.com/GridDesignsGeneratedByLangtonsAnt/​
​
​https://mathworld.wolfram.com/CellularAutomaton.html​
​
​https://demonstrations.wolfram.com/MulticoloredTurmites/

CITE THIS NOTEBOOK

Deep dive into Langton's Ant​
by Loric Bobon & Ellande van Egmond Dascon​
Wolfram Community, STAFF PICKS, September 4, 2025
​https://community.wolfram.com/groups/-/m/t/3540323