Fun with cellular automata - creating patterns and structures with turing termite code written in Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
generatedimages
.gitignore
AutomatonAnimator.java
AutomatonImage.java
Client.java
DisplayableAutomaton.java
README.md
Turmite.java

README.md

Turing Termites

Description of code

I only added two extra files to the code provided - Client.java and Turmite.java. Turmite is a class that extends DisplayableAutomaton and handles all the stepping and drawing logic for a turmite. Client is the client class that creates turmite objects, creates rules for them, makes them step, and saves the output.

The Turmite file keeps track of several things, including the ant's current coordinates, the map of colored squares, the current state, and the current direction. Each step, it applies the current rule (which is passed into the constructor), colors the cell on the image, moves forward, and updates the image.

The client file creates turmite objects with different rules, which are just represented as a 2d array of color-state pairs and the corresponding new color, new state, and direction. Random rules are generated by choosing random amounts of states and colors, then choosing random effects for every color-state pair.

Part 1 - Langton's ant

All these examples can be found in the folder generatedimages. The format of the rulesets is a 2d array, where each row is a rule whose indexes are:

  • 0 - color
  • 1 - state
  • 2 - new color
  • 3 - new state
  • 4 - turning direction

The behaviour of Langton's ant is a bunch of chaotic, seemingly random movements for several thousand steps, after which the ant trails off in sort of a zig-zag pattern. Because the board loops around, the ant re-appears in the opposite corner of where it left the board, eventually colliding into the initial random cluster. If the board was infinite, the ant would go off in the same direction forever.

After 100 steps ... not much interesting happening Langton 100

After 1k steps ... a confusing cluster has started to form Langton 1k

After 10k steps ... the beginnings of the periodic line-like thing start to form Langton 10k

After 1000k steps .. Langton ant is ready to run off into the sunset Langton 100k

Ruleset for Langton's ant =
[color, state, new color, new state, turning direction]
[[0, 0, 1, 0, 0],
[1, 0, 0, 0, 1]]

Part 2 - Classifying randomly generated rulesets

Class I - homogeneous state

Tiny flowers! This is a homogenous state because the ant just draws the four flowers and then "stops" moving - really it is just making useless moves that don't change anything on the board.

Random ant 21

Ruleset for #28 =
[color, state, new color, new state, turning direction]
[[0, 0, 3, 4, 0], [0, 1, 1, 4, 0], [0, 2, 3, 4, 0], [0, 3, 3, 4, 1], [0, 4, 5, 1, 1], [0, 5, 2, 0, 1], [0, 6, 3, 1, 1], [1, 0, 0, 5, 0], [1, 1, 0, 3, 1], [1, 2, 5, 3, 0], [1, 3, 5, 0, 1], [1, 4, 4, 0, 0], [1, 5, 1, 3, 1], [1, 6, 0, 2, 1], [2, 0, 3, 4, 0], [2, 1, 0, 1, 0], [2, 2, 1, 5, 1], [2, 3, 3, 3, 1], [2, 4, 0, 6, 0], [2, 5, 2, 0, 0], [2, 6, 3, 6, 1], [3, 0, 1, 2, 1], [3, 1, 3, 2, 1], [3, 2, 2, 5, 1], [3, 3, 0, 6, 0], [3, 4, 0, 4, 1], [3, 5, 2, 1, 0], [3, 6, 5, 2, 1], [4, 0, 1, 0, 1], [4, 1, 0, 0, 1], [4, 2, 1, 1, 0], [4, 3, 2, 0, 0], [4, 4, 3, 6, 1], [4, 5, 4, 1, 0], [4, 6, 1, 3, 0], [5, 0, 3, 0, 0], [5, 1, 3, 5, 0], [5, 2, 1, 2, 0], [5, 3, 1, 1, 0], [5, 4, 5, 1, 0], [5, 5, 4, 1, 0], [5, 6, 1, 2, 0]]

Class II - stable or periodic simple structures

This is a stable periodic structure because, like the Langton Ant, this ant just draws a line off in the distance forever. Had the board not wrapped around, it would just continue going on.

Random ant 0

Ruleset for #0 =
[color, state, new color, new state, turning direction]
[0, 0, 0, 2, 1],
[0, 1, 2, 3, 1],
[0, 2, 4, 5, 1],
[0, 3, 2, 1, 0],
[0, 4, 3, 0, 1],
[0, 5, 4, 0, 0],
[1, 0, 2, 1, 0],
[1, 1, 4, 3, 1],
[1, 2, 0, 0, 1],
[1, 3, 2, 4, 1],
[1, 4, 0, 4, 0],
[1, 5, 0, 1, 0],
[2, 0, 0, 1, 1],
[2, 1, 1, 5, 1],
[2, 2, 4, 5, 1],
[2, 3, 3, 0, 0],
[2, 4, 0, 0, 1],
[2, 5, 0, 1, 1],
[3, 0, 4, 0, 0],
[3, 1, 2, 0, 1],
[3, 2, 2, 2, 0],
[3, 3, 3, 3, 1],
[3, 4, 3, 0, 1],
[3, 5, 1, 0, 1],
[4, 0, 0, 3, 0],
[4, 1, 0, 0, 0],
[4, 2, 4, 4, 1],
[4, 3, 1, 2, 1],
[4, 4, 3, 3, 1],
[4, 5, 4, 5, 0]

Class III - chaotic pattern

This is a chaotic pattern - it may be possible that the ant starts to display some sort of pattern, but at 300k steps, it seems unlikely that any sort of non-chaotic pattern will emerge.

Random ant 96

Ruleset for #96 =
[color, state, new color, new state, turning direction]
[[0, 0, 9, 11, 0], [0, 1, 5, 4, 0], [0, 2, 5, 1, 0], [0, 3, 4, 2, 1], [0, 4, 1, 4, 0], [0, 5, 9, 5, 1], [0, 6, 4, 2, 0], [0, 7, 2, 7, 1], [0, 8, 8, 10, 0], [0, 9, 6, 9, 0], [0, 10, 10, 0, 1], [0, 11, 5, 8, 0], [1, 0, 4, 8, 0], [1, 1, 4, 0, 0], [1, 2, 6, 8, 1], [1, 3, 5, 8, 0], [1, 4, 4, 0, 0], [1, 5, 8, 8, 0], [1, 6, 10, 9, 1], [1, 7, 6, 11, 0], [1, 8, 5, 0, 1], [1, 9, 2, 3, 0], [1, 10, 3, 7, 0], [1, 11, 2, 4, 1], [2, 0, 5, 6, 1], [2, 1, 2, 3, 0], [2, 2, 7, 5, 0], [2, 3, 1, 0, 1], [2, 4, 4, 10, 1], [2, 5, 3, 6, 0], [2, 6, 7, 7, 1], [2, 7, 2, 1, 1], [2, 8, 2, 4, 1], [2, 9, 4, 8, 1], [2, 10, 10, 0, 1], [2, 11, 9, 3, 0], [3, 0, 3, 5, 0], [3, 1, 9, 4, 0], [3, 2, 0, 0, 0], [3, 3, 5, 4, 0], [3, 4, 9, 3, 0], [3, 5, 8, 7, 0], [3, 6, 3, 3, 0], [3, 7, 5, 9, 0], [3, 8, 9, 2, 0], [3, 9, 10, 7, 1], [3, 10, 9, 3, 0], [3, 11, 8, 0, 0], [4, 0, 6, 5, 0], [4, 1, 4, 3, 1], [4, 2, 4, 4, 0], [4, 3, 9, 0, 1], [4, 4, 9, 7, 0], [4, 5, 3, 10, 0], [4, 6, 10, 5, 0], [4, 7, 1, 7, 1], [4, 8, 7, 2, 0], [4, 9, 1, 11, 0], [4, 10, 1, 3, 0], [4, 11, 3, 10, 0], [5, 0, 8, 6, 0], [5, 1, 8, 0, 1], [5, 2, 7, 6, 0], [5, 3, 2, 5, 1], [5, 4, 4, 4, 0], [5, 5, 10, 1, 1], [5, 6, 1, 11, 0], [5, 7, 4, 2, 1], [5, 8, 0, 4, 1], [5, 9, 9, 10, 0], [5, 10, 8, 10, 1], [5, 11, 10, 1, 0], [6, 0, 4, 6, 1], [6, 1, 8, 11, 0], [6, 2, 0, 8, 1], [6, 3, 8, 6, 1], [6, 4, 9, 9, 1], [6, 5, 10, 5, 0], [6, 6, 7, 1, 1], [6, 7, 10, 6, 1], [6, 8, 9, 3, 1], [6, 9, 10, 11, 1], [6, 10, 6, 9, 0], [6, 11, 7, 4, 0], [7, 0, 7, 10, 0], [7, 1, 9, 2, 1], [7, 2, 4, 1, 0], [7, 3, 8, 0, 0], [7, 4, 9, 7, 0], [7, 5, 5, 5, 0], [7, 6, 10, 9, 0], [7, 7, 6, 2, 1], [7, 8, 1, 8, 0], [7, 9, 1, 9, 0], [7, 10, 4, 9, 0], [7, 11, 1, 1, 1], [8, 0, 9, 6, 1], [8, 1, 4, 5, 1], [8, 2, 1, 5, 0], [8, 3, 4, 11, 0], [8, 4, 2, 2, 0], [8, 5, 7, 0, 1], [8, 6, 3, 2, 1], [8, 7, 4, 9, 1], [8, 8, 2, 7, 1], [8, 9, 1, 7, 1], [8, 10, 8, 3, 0], [8, 11, 2, 0, 1], [9, 0, 7, 10, 0], [9, 1, 2, 5, 1], [9, 2, 2, 9, 0], [9, 3, 8, 3, 0], [9, 4, 3, 10, 1], [9, 5, 8, 2, 1], [9, 6, 2, 7, 1], [9, 7, 4, 8, 0], [9, 8, 7, 5, 0], [9, 9, 0, 4, 0], [9, 10, 1, 10, 0], [9, 11, 4, 2, 0], [10, 0, 3, 7, 1], [10, 1, 8, 2, 1], [10, 2, 3, 5, 0], [10, 3, 0, 1, 0], [10, 4, 10, 6, 1], [10, 5, 10, 3, 0], [10, 6, 7, 8, 0], [10, 7, 2, 5, 0], [10, 8, 4, 0, 0], [10, 9, 9, 11, 0], [10, 10, 2, 11, 1], [10, 11, 10, 10, 1]]

Class IV - complex structures

I think this qualifies as a complex structure because of the way the perpendicular lines interweave with eachother and occasionally create clusters before zig-zagging off again.

random ant 18

Ruleset for #18 =
[color, state, new color, new state, turning direction]
[[0, 0, 2, 8, 1], [0, 1, 1, 3, 1], [0, 2, 5, 10, 1], [0, 3, 5, 4, 0], [0, 4, 4, 0, 0], [0, 5, 0, 10, 0], [0, 6, 2, 4, 0], [0, 7, 0, 10, 1], [0, 8, 0, 6, 1], [0, 9, 5, 10, 1], [0, 10, 3, 5, 1], [0, 11, 4, 5, 1], [1, 0, 1, 3, 1], [1, 1, 3, 2, 0], [1, 2, 5, 7, 1], [1, 3, 5, 3, 0], [1, 4, 3, 2, 1], [1, 5, 1, 7, 1], [1, 6, 0, 1, 1], [1, 7, 5, 10, 0], [1, 8, 2, 7, 0], [1, 9, 5, 9, 0], [1, 10, 4, 7, 0], [1, 11, 0, 5, 1], [2, 0, 1, 1, 1], [2, 1, 1, 2, 0], [2, 2, 3, 10, 0], [2, 3, 0, 9, 1], [2, 4, 0, 8, 0], [2, 5, 3, 2, 0], [2, 6, 0, 5, 1], [2, 7, 3, 3, 1], [2, 8, 0, 6, 1], [2, 9, 2, 11, 0], [2, 10, 3, 1, 1], [2, 11, 4, 10, 0], [3, 0, 2, 4, 0], [3, 1, 1, 11, 1], [3, 2, 3, 7, 1], [3, 3, 5, 1, 0], [3, 4, 5, 10, 0], [3, 5, 3, 9, 1], [3, 6, 2, 6, 0], [3, 7, 1, 6, 0], [3, 8, 2, 4, 1], [3, 9, 5, 5, 1], [3, 10, 5, 1, 1], [3, 11, 1, 8, 0], [4, 0, 4, 4, 0], [4, 1, 2, 9, 0], [4, 2, 0, 7, 0], [4, 3, 4, 11, 1], [4, 4, 3, 0, 0], [4, 5, 4, 9, 0], [4, 6, 4, 11, 0], [4, 7, 0, 4, 1], [4, 8, 3, 10, 1], [4, 9, 4, 2, 0], [4, 10, 4, 4, 1], [4, 11, 5, 2, 0], [5, 0, 0, 0, 1], [5, 1, 0, 0, 1], [5, 2, 2, 2, 1], [5, 3, 0, 0, 0], [5, 4, 3, 10, 1], [5, 5, 2, 5, 1], [5, 6, 2, 7, 1], [5, 7, 5, 7, 1], [5, 8, 2, 6, 0], [5, 9, 1, 6, 1], [5, 10, 4, 7, 0], [5, 11, 1, 2, 1]]

Bonus extra images that I thought were cool: random ant 28

random ant 25

Part 3 - Generating a spiral

The spiral works by continously moving forward and coloring blocks if the current block is empty and the state is 0. A block is never colored back to white (or turned empty after it has been filled). The ant traces the outer edge of the current structure until the point that it hits another black block, which will happen if it is time for the next leg of the spiral to grow longer. Turns are decided on the edges of the square spiral - usually they are left (0) on a corner, but when it steps on a block that has already been colored in with a state of 1 (so, colored in by itself and previously passed by itself only once), it will turn right off that block and then left again ... so the spiral continues around, the next leg a pixel longer.

spiral

Ruleset for spiral =
[color, state, new color, new state, turning direction]
[[0, 0, 1, 1, 0],
[0, 1, 1, 0, 2],
[1, 0, 1, 0, 2],
[1, 1, 1, 0, 1]]