Langton’s Ant & Musical Patterning II

Jeff Holtzkener
11 min readJan 27, 2024

--

Continued from Langton’s Ant & Musical Patterning I

Part II — Musical Patterning

What is ‘musical’ in Langton’s Ant Family Cellular Automata

There are some characteristics in the patterns that emerge with Langton’s Ant type CA make them interesting candidates for musical sonification:

  • The highways often display periodicity, and these translate nicely into repeated motifs and patterns
  • If an ant encounters an existing highway (either because the grid is a Pac-Man style torus, or because there are multiple ants), they will sometimes repeatedly weave new patterns with different periodicity into the existing ones, then weave new patterns on their next encounter and so on. The patterns emerging from weaved patterns are both new yet familiar
  • Symmetry and reverse symmetry emerge with some rule systems and this is interesting musically: a pattern is articulated, then later the pattern is ‘undone’, that is, repeated in reverse.
  • Rotations occur for some rules especially for the hexagonal grid. In a way, a rotation is a transposition, like starting a theme on a different scale degree

When I first developed an interest in Langton’s Ant in 2016, I was a novice self-taught programmer and developed a free iOS app that let users experiment with different rule systems, and also allowed for mapping the ant’s direction to either a musical scale (played by a MIDI soundfont) or a handful of percussion samples. I was contacted last summer by a composer named Andrew Byrne who used the my app to generate a series of pieces during COVID. His results are interesting, but hearing them made me reflect on why I had used the ant’s ‘direction’ as the sole parameter within the options available to map to sound. The honest answer is that at the time, it was easier for me to make UI components to map direction to sound than the other parameters I could think of. In retrospect, I was leaving out important possibilities. As I see it now, there are actually three great parameter ‘pattern catching’ candidates for mapping to sound.

Strategies for mapping patterns to sound

  • Mapping cell state — each time a cell changes state, we can play a pitch or a sample that corresponds to that state. The number of states would determine the number of pitches, which means that this will be limited when there are only two states in our system (like, for example, the original Langton’s Ant model). But we can always repeat a rule sequence, for example, if the rule LR patterns interestingly, then so will LRLR, and LRLRLR, and so on, which can give a richer sound palette to work with, maintaining the fundamental character of the pattern that emerges. The advancement of cell states is where the most interesting and insistent patterns form. Also it’s perceptually salient: it creates the strongest correlation between what we see and what we hear — each colour has it’s own sound. A one-to-one pitch mapping for 8 states might look like this:
  • Mapping absolute ant direction — each possible ant direction is mapped to a pitch or sample. For the traditional square grid ant, we have four directions, and each time the ant moves in that absolute direction, it triggers some pitch or sample. The number of available mappings here corresponds to the grid shape. Rotations, which occur with some rules, can function like transpositions when we map the direction: the same pattern but starting on a higher scale degree. But the only practical way to handle directions is using modular arithmetic so that analogy falls apart somewhat (i.e., there is no way to distinguish between 360° and 0° — so when we might expect a pitch to rise to the next ‘octave’ it falls back to the root.)
An example of mapping 4 directions to 4 pitches
  • Mapping the rule application (the change of direction) — we once again map one pitch or sample to each possible direction for our grid, but we sound out the change of direction given by the rule, not the absolute direction of the ant. So for example, in the canonical Langton’s Ant with the rule LR, each time the ant turns left we make one sound, and each time it turns right we make another, regardless of the direction the ant is facing. In contrast to Absolute Ant Direction, which will have four values (for N,E,S,W) — all of which will likely be used equally — there are only two values being applied by the rule (L and R). It’s a smaller palette (few interesting rules use all of their directions) so this approach works better with samples than pitches. Each state has one rule application, so these two mappings will be closely linked (although a single rule application may be used for multiple states.)

One of reason why these systems are so rich for patterning sound is that we don’t have to choose between the different strategies. Each approach captures one important aspect of the overall emergent pattern. The relationship between the absolute direction and the either the cell state or the rule application can be quite complex. They are interlocking patterns — they generally move in and out of periodicity together, but with different behaviours at each level. Also they are causally related in both directions — the cell state and rule application impact the direction, while direction impacts the cell that changes state. The mgic comes in hearing them all together.

Other mapping candidates:

  • ‘Total system mass’ — Imagine the sum of the numeric value of the states of the cells in a system as the ‘mass’: an empty system where all the cells are at state 0 would have a mass of 0. If there were three cells at state 1 and one cell at state 2, it would have a total mass of 5. Rule systems often increase their ‘total mass’ as the entropy increases, and many systems grow indefinitely if given enough room. I’ve played around with using ‘total mass’ as a timbral parameter with filters and other effects.
  • Absolute Ant Position — the x and y coordinates for an ant could also be mapped to some kind of sound parameter. I suppose one (or both?) of these could be pitch as the y coordinate is in this great example . Mapping either one of these axes to some timbral parameter, for example, a filter, would also make sense: as the ant moves right, it could open up a low pass filter and close it as it moves left.

Approaching Rhythm

Cellular Automata typically generate an event or events at each iteration, and translating every step into an aural event will mean an unceasing flow of notes coming at a fixed time interval. Regardless of what interesting patterns it contains, the result will likely feel exhausting and monotonous. Extracting patterns that allow for more rhythmic variation — or better yet, highlight existing patterns through rhythmic variation — really makes the sonifications more listenable. Here are two strategies I like:

  • Only trigger events when something changes: Instead of triggering auditory events at every step, we can trigger them only when the event is different from the one that preceded it. This is a technique that I’ve often used with other cellular automata but it works especially well here. I don’t always use it with direction, but I nearly always used it with state.
The opening phrase of the Square LRRL rule (first video linked below), generated from the state
  • Leaving a gap in the mapping: this was something that I heard in one of Andrew Byrne’s pieces and I thought it added nice rhythmic variation. In my opinion, the most natural, non-arbitrary choice for this empty mapping is the initial state in the Cell State mapping approach I described above. At the initial time step, all the cells are in their initial state, for which a colour close to black or white is usually chosen. Of course, this is arbitrary, but this is effectively the background colour. As the ant begins to move, the cells will move from this default state to their second state, and the first sound you will hear will be the second mapped sound — if that mapping is, for example, a major scale, you will first hear the second degree of the scale first, and you won’t actually get to hear the root note until some cell has cycled through all its states. In which case, we’re actually hearing the dorian mode. By mapping the initial state to a rest, and mapping the first scale degree to the 2nd state, we can avoid that. Because the rests co-occur with the background colour, it also adds to the perceptual connection between the visual and auditory mappings. A state mapping that ignored the initial state might look like this:

My best results

Simple Symmetries on a Cartesian Grid

These two systems are done on a simple 4-way grid and both generate beautiful symmetry. The two patterns are using the same audio configuration — all I did was change the rule and the colours.

The first one has the four states mapped to four gamelan samples pitched to roughly D: black, F: yellow, A: brown, and C: grey, and there are four percussion samples mapped to the four directions. When it starts, it cycles through its states creating a cute little musical phrase.

Then the ant goes on an adventure of some length on the left side, sometimes short, but sometimes a few minutes long. At some point it crosses over to the right and making all the same modifications, but in precisely the reverse order, then it finally that it comes back to the centre and becomes symmetric once again. At that point, it returns to the little musical phrase. The first two bars are more or less the same each time, but the subsequent events are hitting cells that are already in different configurations of states, so it diverges, although the same rhythmic pattern tends to recur. The percussion, sounding the direction of the ant, tends to group together in chunks of 4, which is reflecting the fact that the ant is redrawing a square in the middle of the grid (while the patterns emerging from the state are often in groups of 5 when it restarts.)

Symmetry on a Hexagonal grid

The rule LR (and its multiples like LRLR) will also create the same kind of symmetry with the hexagonal grid, but the rule LLRR makes something really special. Like the examples above, it has something like an ‘opening theme’: a pattern that it creates when the centre is back to the initial state.

Like the examples above it also goes on these little or big adventures, breaking the symmetry, usually tracing a pattern on the lower half, then eventually passing through the upper half, tracing the same pattern but in reverse order. But it has an extra characteristic: there are two flavours of the little adventure that it takes. One alternates between the 4th and 2nd states (white and dark purple, musically B and E) for some length of time, and then it switches to alternating between to the 3rd and initial state (pink and black, musically G and C), then back to the 4th and 2nd, and so on. My ear fills in all some details and hears a repeated alternation between a E minor and C major chord. The longer it holds on a single chord, the more tension builds. This wasn’t intentional (I expected an amorphous Cmaj7), it was a discovery, but I like the effect.

Collisions

For this system I used a hexagonal grid with the rule L2 L2 L2 R R R. The patterning that this creates is really wonderful, but falls into a highway after a few hundred steps. It’s an interesting highway, but in theory would just proceed indefinitely with the same periodic pattern. It can actually do so much more when it interacts with itself. So I used two ants with different starting directions and positioned them so that their highways would collide. Until ~3:00 the two ants are completely in unison, but after the collision they interact with each other independently, creating new patterns, returning to make new highways, only to collide again, make more new patterns, more highways and so on.

This next one is possibly my favourite, although it has much fewer views than the others. It uses an 8-way system (a cartesian grid, but it can move diagonally, here R1 means 45°, and R2, 90°). The basic rule is R2 L2 R1 L1, but repeated twice, so that I can have access to more pitches by doubling the number of available states (R2 L2 R1 L1 R2 L2 R1 L1). It starts out of the gate making a highway with a period of 13. Like the example above, it also interacts beautifully when colliding with itself, generating all sorts of interesting periodic patterns which create cross-rhythms with the patterns generated by the partner ant. I don’t want to anthropomorphize the system’s behaviour (or “myrmecomorphize” in this case — thanks ChatGPT) but it feels like it desperately wants to make patterns

References

Langton’s Ant Family Cellular Automata — this is the free iOS app I made in 2016. I haven’t updated it it years, nor will I, but it’s still fun to play with. You can input rules for square (including eight-way) and hexagonal grid and also map ant direction to a few scales or percussion samples. App names aren’t allowed to be that long any more; I’d need to change it, if I updated.

Langton’s Ant on Wikipedia — it’s not a massive article, but some of the rules it includes are fantastic, and I don’t know where else I would have discovered them.

brmtr’s Hexagonal Langton’s Ant — This was a hugely useful resource for me when I first discovered hexagonal geometries. Also has some neat hexagonal rules as examples that I haven’t seen elsewhere.

Andrew Byrne’s Ants — a series of musical pieces (recordings, videos, and scores) using the direction mapping approach from my app

Expensive Note’s Teensy Controlled Langtons Ant Sequencer with Launchpads, Volca FM, Volca Bass and NTS-1 — if I understand correctly the ant’s y position maps the main pitch, while the state of the system at each x position is ‘sampled’ sequentially. Watch it — its a real treat

The shambolic Open Processing sketch I actually used for most of the videos — It just kept evolving and its more or less unreadable

Github link with the currently maintained version of the code for the videos, rewritten in typescript

--

--