Recamán’s sequence is a very fascinating sequence of integers arising from the following rules:
|a(0) = 0|
|a(n) = a(n-1) - n||for n > 0, if positive and not already in the sequence,|
|a(n) = a(n-1) + n||otherwise.|
The animation shows the development of the sequence by connecting consecutive elements by alternating upper and lower arcs. The number line is slanted 45 degrees upwards, as this uses the available space very nicely and is, to me, aesthetically more pleasing.
In addition, the numbers of the sequence are also ‘translated’ to piano notes. As the range of a piano includes 88 keys, the numbers of the sequence will be played modulo 88 - this is also nicely explained in the very good Numberphile video about this sequence.
More details and history of the sequence can be found at the On-Line Encyclopedia of Integer Sequences.
As can be seen, the type of representation I am using is not a new idea, neither the representation of the data as audio (‘sonification’), but possibly the type of animation shown here is new and pleasing: whereas animating the steps of the sequence with arcs is quite straight forward, I tried different approaches to highlight the crossing of the arcs with the bisecting line and the corresponding piano notes, representing the elements of the sequence.
In the end I settled for something closer to hitting individual ‘keys’ of a piano as shown in the animation at the top, as this also seems to fit the piano sound the best.
On the technical side, this is my first animation using OpenRNDR, a very nice and rather new open source framework for creative coding (based on the Kotlin programming language). For the sound I am using JFugue and the FluidR3_GM.sf2 midi compatible soundfonts.
The following still images show Recamán’s sequence up to 51, 98, 169 and 200 elements:
The first two images seem to be closely self-similar - but I don’t know whether there is any significance to this. Searching the interenet for self-similarity and Recamán does not show any obvious hits at least.
The OpenRNDR/Kotlin code can be found on Github (though bear with me, this is my first OpenRNDR/Kotlin project).