Blog edition
vers. 1.2.19

the Nailbox

Honeypot for bots. Don't submit or you'll get banned!

[back]

Ants

2010-06-29 11:31 by Nailbar
Got carried away reading about cellular autonama so I decided to make my own ant farm.

It works in Firefox and uses the HTML5 canvas so in theory it should work on any HTML5 enabled browser.

Enjoy!

ants.html

Basically it generates a couple of ants with a random set of 8 genes which dictates what color the underlying pixel will turn into, and how the ant will move to the next pixel, depending on what color the current pixel is.

Click Zap to mutate an ant, and Kill to restart an ant in a new place with completely random genes.

The eight genes are sets of three numbers each; Activation color, New color, Action. If a gene is "641" then this means that if the ant steps on a pixel with color 6, then it will turn that pixel into color 4, and turn right.

Action codes; 0=forward, 1=turn right, 2=turn left, 3=reverse.

For example, the gene set of 022,152,201,372,440,562,620,721, which was generated randomly by the program, turned out to be Langton's Ant:

langtons_ant.jpg

Since JavaScript is very hackable, here's the code to make one of the ants into Langton's ant:

javascript:a[0].g1=[2,5,0,7,4,6,2,2]; a[0].g2=[2,2,1,2,0,2,0,1]; a[0].x=400; a[0].y=300; updategenes(0);

Just copy-paste into the browsers address bar and press Return while the program is running. You may need to tweak the a[0].x, and a[0].y parts to place the ant in an empty spot so it won't tangle up with other ants.

Update

Updated the ant program so it's not limited to a fixed number of ants or genes.

ants.jpg

ants-1.1.html

[Add comment]

by Martin Wikström

Updated: 2010-06-29 11:31