The Collatz Conjecture is one of nature’s coolest algorithms. It has a very simple rule: if a number is even, divide by 2; if it’s odd, multiply by 3 and add 1; repeat until 1 is reached. This lends itself to some beautiful art.

How can such a simple alogirthm become art? A single Collatz sequence can be represented as a vector of numbers. If you take the reverse of the vector, it starts at a value of 1. It then progresses through a series of numbers back to the number that started the sequence. Now imagine, as the sequence progresses through each number, a line grows from the starting point. The distance it grows at each new number is constant, however, the line bends one way if the number is even and bends the opposite way if the number is odd. You ultimately get a curvy line.

Now imagine plotting dozens or hundreds of these lines together, each with different starting numbers (but all still ending at 1). That’s where the magic happens, and where flowy, organic visualizations appear.

Bringing the Collatz to life is simple thanks to the aRtsy R package. The most basic code is shown below:

library(aRtsy)

set.seed(1)
canvas_collatz()

In the above code, I did not specify any additional parameters to the function. But there are plenty of options for customizability:

  • n: the number of random starting integers to use for lines
  • colors: colors to use for the artwork
  • angle.even: a value specifying the angle (in radials) to use in bending the sequence at each odd number
  • angle.odd: a value specifying the angle (in radials) to use in bending the sequence at each even number

Here’s one visual I created based off of 200 lines:

collatz-digital

Now what’s better than digital art? Physical art. The brilliant minds over at Drawscape were able to take the concept from screen to paper with their robot plotting machines.

collatz