After watching a documentary about Alan Turing, I started thinking about Turing machines again. They’re a very useful tool for computer science proofs and an elegantly simple computational model. Beyond this, however, Turing machines seem relatively useless in terms of “real-world” applications. Any computable function can be computed by a Turing machine, but you probably wouldn’t want to use one as a compilation target: it would be too inefficient.

One possible application for Turing machines is to use them as programs to generate data procedurally. Their simplicity makes it possible, for example, to create working programs randomly. Generating a random stream of x86 instructions that doesn’t crash could be tricky, but with a Turing machine, it’s quite easy. I decided to try something like this to produce so-called generative art. The program I wrote generates random Turing machines that operate on a two-dimensional grid instead of a one-dimensional tape. The symbols written on the grid can be interpreted as colors, and voilà: we have procedural drawings.

I prototyped this in JavaScript and named the project Turing Drawings. This is available on GitHub if you’re interested in seeing the source code. Better yet, I put a live demo up on GitHub pages (first time trying gh-pages, works great!) and I started collecting a list of interesting patterns produced by Turing Drawings:

Last night, by chance, I randomly generated something that looked very much like the Sierpinski fractal, but unfortunately lost the encoding for that one. If you happen to find fractal patterns, be sure to let me know!

EDIT: seems the people on reddit.com/r/compsci have gotten pretty excited about this. I’m surprised at how much of a positive response I got. Here are some of the nicest patterns they’ve found:

For future work, I’m thinking it might be interesting to try using Turing machines to generate music procedurally. Certainly, music could be represented by notes on a tape, or even multiple tapes.