アニメーション

(*パラメータ設定*)size=101;
maxSteps=11500;
frameInterval=20;
frames={};

(*初期化*)
grid=ConstantArray[0,{size,size}];
antPos={Ceiling[size/2],Ceiling[size/2]};
antDir={0,1};
turnLeft={{0,1},{-1,0}};
turnRight={{0,-1},{1,0}};

Do[currentColor=grid[[Sequence@@antPos]];
grid[[Sequence@@antPos]]=1-currentColor;
antDir=If[currentColor==0,turnRight.antDir,turnLeft.antDir];
antPos+=antDir;
antPos=Mod[antPos-1,size]+1;
If[Mod[step,frameInterval]==0,AppendTo[frames,ArrayPlot[ReplacePart[grid,{antPos}->2],ColorRules->{0->White,1->Black,2->Red},Frame->False,Mesh->True,(* ←グリッド線を表示*)MeshStyle->GrayLevel[0.8],ImageSize->300]];],{step,1,maxSteps}];

(*アニメーション表示*)
ListAnimate[frames,DefaultDuration->20]


Export["LangtonsAnt.gif",frames,"DisplayDurations"->0.05]

Directory[]

SystemOpen[DirectoryName[AbsoluteFileName["LangtonsAnt.gif"]]]

SystemOpen[DirectoryName[AbsoluteFileName["LangtonsAnt.gif"]]]

SystemOpen[DirectoryName[AbsoluteFileName["LangtonsAnt.gif"]]]