Page 1 of 1

Another ant-based cellular automata

Posted: January 18th, 2019, 2:28 am
by PHPBB12345
https://codepen.io/anon/pen/vvqNqg
These rule makes mysterious path!

Re: Another ant-based cellular automata

Posted: January 27th, 2019, 2:08 am
by Redstoneboi
the step function:

Code: Select all

function next_step()
{
	var dx = x_shift[ant_d];
	var dy = y_shift[ant_d];
	var cx = (ant_x+dx+w)%w;
	var cy = (ant_y+dy+h)%h;
	
	var a = cy*w+cx;
	var s = currc[a];
	if (s)
		ant_d = (ant_d + 3) % 4
	else
		ant_d = (ant_d + 1) % 4
	currc[ant_y*w+ant_x] = 1 - s;
	ant_x = cx;
	ant_y = cy;
declarations:

Code: Select all

var ant_x = (w / 2) | 0;
var ant_y = (h / 2) | 0;
var ant_d = 0;
var currc = new Uint8Array(w*h);

var x_shift = [1,0,-1,0];
var y_shift = [0,1,0,-1];
after analysis, the rule seems to:
write down the next position as cx and cy,
change the direction similar to langton's ant,
toggle the cell at cx and cy,
move to cx and cy,
repeat.

simplification leaves this:
flip cell,
change direction according to cell behind,
move forward,
repeat.

which is basically:
langton's ant but it looks behind instead of under.