Turmites

Turmites are miniature computers. They read the colour of the square that they are sat on. They then set the colour of that square before moving in a particular direction. Though this instruction set is very small turmites are capable of very complex calculations. There is no short cut to calculating what a particular turmite will do. The quickest way to find out what it does is to run it and see. This concept lies at the core of Turing's halting problem and his version of Godel's incompleteness theorem.

Use the code below to first make program s. You need s to colour in the squares under the turmite.
Then make program main. This creates a turmite.

To make further turmites it is probably best to copy your first main section and rename it main2 etc.
Then alter the central block of if statements to produce new turmites.

Setting the Fill Color using an Index

This codedraws a square and fills it in. The code draws a square about the current turtle position. The code has two arguments; :size sets the edge of the square and :col 0-15 sets the fill color.

to s :size :col
pu bk :size/2 pd
lt 90
fd :size/2
repeat 3 [rt 90 fd :size]
rt 90 fd :size/2
pu rt 90 fd :size/2 pd
setfloodcolor :col fill
end

Test the code by typing s 200 2 etc.

If this doesn't work at first try cs to clear the screen.
You might also need to reset the fill colour with setfc 9, or the pencolour with setpc 9.

Reading the Color from the Pixel Beneath the Turtle

Reading a color from the screen is an essential skill for basic games. This code reads the color from the turtle position and uses this to decide what color to leave behind and which direction to move the turtle off in.
This program is actually a Turmite; these are a whole class of little programs which were very important in the development of computer science.

to main :size
cs
setpensize [1 1]
setpencolor 9
setfloodcolor 0
fill
repeat 100000 [
make "col pixel
if :col = 0 [ s :size 1 lt 90 pu fd :size pd ]
if :col = 1 [ s :size 0 rt 90 pu fd :size pd ]
]
end

The pixel command returns the color value of the pixel at the turtle position.
The program then draws a square using s of the correct color before moving off in a given direction.
This particular turmite seems to wander at random for a few 1000 moves before locking into a repeating pattern.
The argument :size simply sets the cell size.


Turmites are capable of extremely complex behaviour. This example locks into a steady pattern that expands outwards forever. The example above shows regions of very ordered behaviour and other regions of seeming chaos. The interaction of order and chaos makes these fascinating systems to study.

Turmite with core code;
if :col = 0 [ s :size 1 lt 90 pu fd :size pd ]
if :col = 1 [ s :size 2 rt 90 pu fd :size pd ]
if :col = 2 [ s :size 3 rt 90 pu fd :size pd ]
if :col = 3 [ s :size 1 pu fd :size pd ]
See below for details.

This turmite produces a pattern with both chaotic and ordered elements. It seems to be infinite in that it gradually expands to fill the plane. Does it ever stop?

Turmite with core code;
if :col = 0 [ s :size 1 lt 90 pu fd :size pd ]
if :col = 1 [ s :size 2 rt 90 pu fd :size pd ]
if :col = 2 [ s :size 3 rt 90 pu fd :size pd ]
if :col = 3 [ s :size 4 rt 90 pu fd :size pd ]
if :col = 4 [ s :size 5 rt 90 pu fd :size pd ]
if :col = 5 [ s :size 1 pu fd :size pd ]

There are an infinite number of turmites to play with. Their behaviour boils down to 4 main classes. Can you find all four?
Can you alter the program so that two or more turmites run at the same time?
What happens if you turn the space into a toroid so that the turmite comes back at the bottom if it runs of the top edge?
Can you make a hexagonal turmite?
Can you make turmites based on the 8 semi-regular tesselations of the plane?
What shape is the space if hexagonal turmites wrap around the edge of their plane?

Last updated 3rd February 2012