Hexagonal Ants
A continuation of github:jcorbin/ants, now on hexagons.
Beyond click to play/pause, UI is currently keyboard and URL-fragment driven only:
<Space>
-- play/pause.
-- single step when paused, pause when playing/
-- prompt and set new rule setc
-- prompt and set new color schemet
-- toggle "trace mode" drawingt
-- toggle drawing of unvisited cells+
-- double step rate-
-- half step rate*
-- reset to iteration 0 and pausef
-- show/hide frames and steps per second (fps and sps)#
-- toggle labels for debuggingThe language for specifying ants is:
ant( [<count>]<turn> ... )
Essentially it's simple RLE-encoded turn sequences inside ant(...)
, some
examples:
ant(L R)
ant(2R 10F 2R)
The possible relative turns are:
L
-- to the leftR
-- to the rightF
-- forward (no turn)B
-- backward (reverse direction)P
-- "port", rear left turnS
-- "starboard", rear right turnThe possible absolute turns are:
NW
-- North WestNO
-- NorthNE
-- North EastSE
-- South EastSO
-- SouthSW
-- South WestPlease excuse the abuse of "port" and "starboard" towards the end of unique single-character letters ;-)
Ants are a special case of a Turmite:
Internally turmites are implemented as a 65536-element 32-bit lookup table.
state << 8 | color
where:
state
is the turmite state bytecolor
is the world color bytestate << 24 | color << 16 | turn
where
state
is the next turmite state bytecolor
is the world color byte to writeturn
is a 16-bit field indicating the turn(s) to take (only 12 of theEXPERIMENTAL: the specification language is still in very early development and may breaking changes may happen at anytime. Additionally the quality of the error messages provided by the parser and compiler reflect its immaturity.
To assist in building this lookup table, a turmite specification language is
provided. As our first example the classic ant(L R)
becomes:
Turns = turns(L R)
0, c => 0, c + 1, Turns[c]
Quirks to note:
OR
ed together by default; you can=
to instead replace any prior valueA more complex example:
T1 = turns(L R)
T2 = turns(2L 2R)
0, c => 0, c + 1, T1[c]
1, c => 1, c - 1, T2[c]
0, 32 * c => =1, 0, 0
1, 32 * c => =0, 0, 0
Colors are driven by a color generation scheme, using a simple language.
light(HUE, SAT)
Uses lightness variation for a fixed hue and saturation in the HSLuv color space.
HUE
is a number between 0
and 360
and is in degrees on the color wheel;0
.SAT
is a number between 0
and 100
and is a percentage; defaults to100
.hue(SAT, LIGHT)
Uses hue variaton for a fixed saturation and lightness in the HSL color space.
SAT
is a number between 0
and 100
and is a percentage; defaults to70
.LIGHT
is a number between 0
and 100
and is a percentage; defaults to40
.rule
-- the rule spec to usecolors
-- the color scheme to usestepRate
-- goal number of turmite steps per seconddrawUnvisited
-- specify to draw every cell in the tree instead of onlylabeled
-- specify to add coordinate labels to cells (doesn't scale well,Just:
$ npm install
$ npm run serve