Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.

Each cell can either be black or white.

The ant moves according to the color of the cell it is currently sitting in, with the following rules:

   If the cell is black, it changes to white and the ant turns left;
   If the cell is white, it changes to black and the ant turns right;
   The ant then moves forward to the next cell, and repeat from step 1.

This rather simple ruleset leads to an initially chaotic movement pattern, and after about 10000 steps, a cycle appears where the ant moves steadily away from the starting location in a diagonal corridor about 10 cells wide.
Conceptually the ant can then walk infinitely far away.



Task

Start the ant near the center of a 100x100 field of cells, which is about big enough to contain the initial chaotic part of the movement.

Follow the movement rules for the ant, terminate when it moves out of the region, and show the cell colors it leaves behind.



The problem has received some analysis; for more details, please take a look at the Wikipedia article   (a link is below)..



See also

   Wikipedia:   Langton's ant.


Related task

   Rosetta Code:   Conway's Game of Life.


 
      REM Implementation of Langton's ant for Rosetta Code
      fieldsize%=100
      REM Being pedantic, this will actually result in a field of 101 square,
      REM since arrays start at 0, and my implementation allows them to use it
      DIM field&(fieldsize%,fieldsize%)   : REM variables with an & suffix are byte variables
      x%=fieldsize%/2
      y%=fieldsize%/2
      d%=0
      REPEAT
        IF field&(x%,y%)=0 THEN field&(x%,y%)=1:d%-=1 ELSE field&(x%,y%)=0:d%+=1
        GCOL 15*field&(x%,y%)
        PLOT 69,x%*2,y%*2     :REM for historical reasons there are two "plot points" per pixel
        d%=(d%+4) MOD 4       :REM ensure direction is always between 0 and 3
        CASE d% OF
          WHEN 0:y%+=1
          WHEN 1:x%+=1
          WHEN 2:y%-=1
          WHEN 3:x%-=1
        ENDCASE
      UNTIL x%>fieldsize% OR x%<0 OR y%>fieldsize% OR y%<0
      END
 