Generative Pills #2: The Music of Pi

Pi () is the most famous irrational number; the circumference of a circle is given by its diameter (two times its ray) multiplied by Pi, but ….

Pi is irrational, this means that its decimal representation NEVER ENDS (there is no “last digit of Pi”) and NEVER REPEATS (never enters a permanently repeating pattern); so it’s also an elusive and mysterious number. Already the ancient Egyptians and Babylonians tried to calculate its value as precisely as possible, and currently we “know” the first 68.2 trillions of digits of Pi (record achieved on 14 August 2021 by Team DAViS of the University of Applied Sciences of the Grisons).

Many artists have tried to use Pi as a source of inspiration, but …. but it is conjectured (we have no formal proof of it) digits of Pi are randomly uniformly distributed in the sense that the digits 0 through 9 appear equally often, as do pairs of digits, trios of digits, and so forth. So if you use a subsequence of decimal digits of Pi to (automatically) generate some “art” , then you should obtain the same result if you use a simple random number generator.


Continue reading

Generative Pills #1: Snakeline Drawings

[This is the first post of a serie dedicated to some ideas of generative art (graphics and music)]

I’ve always been a fan of the videogame Nibbler  and other snake-like videogames (I also “played” with them theoretically … but this is a total different story 😉 ). But can the concept be used for generative art? I had an idea and set up a quick sketch in which many colored snakes freely run around the screen, random food blocks are placed on the screen and whenever a snake eats a food its length increses, when a snake hits another snake or its own tail it tries to change direction … but the result was not so promising; this is an image of the sketch:

Then I tried using a simple line to draw the snake and use another set of rules:


  • a set of “snakes” (drawn as lines) are randomly placed on the screen
  • each snake:
    • has a random color. The color is picked from a finite palette for better results.
    • can move horizontally/vertically/diagonally (for mor interesting results, some of them can move only horizontally/vertically)
    • has a preferred rotation angle (clockwise or counterclockwise)
  • when a snake moves its length increases
  • if a snake hits another snake or its own tail, it tries to rotate and
    continue its run (or stops moving)

… and “magically” the results became more interesting:

I don’t know if its original: the dynamics is similar to the Tron bikes race  and I also found a method to generate paintings in the style of Piet Mondrian by Michael Fogleman (2011), but the results are quite different. So let me know in the comments if someone else has already used this technique.

I used the Snakeline Drawings algorithm to make some videos (please subscribe to my channel):

A showcase of images produced by the algorithm.

A “fractal” tribute to Bach …


The source code can be downloaded here:

snakeline v1.0 source code


Memories of an Electric Sheep

A simulation of the brain activity of an electric sheep: it dynamically combines some of the best paintings ever created.

The memory evolves and the combinations are endless and unique. With a little bit of patience, weird artistic “anachronisms” can arise: an old japanese boat sailing in Venice, a sleeping hawaiian in front of Plato and Aristotle, a clock near the animals in a prehistoric cave …

The animation was exhibited at PDC@Coimbra 2021 a Processing Community Day initiative supported by the Processing Foundation with the goal of celebrating art, code and diversity while promoting creative coding and computational thinking as tools for creative students, researchers and professionals. The theme of the exhibition was “Anachronism”.

The soundscape is purely generative (made in VCV Rack).

The source code can be downloaded here: sheepmemories2.7z


The Endless Tale … (Asemic Writing animation)

From Wikipedia:

Asemic Writing is a wordless open semantic form of writing. The word asemic means “having no specific semantic content”, or “without the smallest unit of meaning”. With the non-specificity of asemic writing there comes a vacuum of meaning, which is left for the reader to fill in and interpret. …. Asemic writing is a hybrid art form that fuses text and image into a unity, and then sets it free to arbitrary subjective interpretations. …

Inspired by a challenge launched by Robert Boran on the Facebook group Creative Coding with Processing and P5.js I created a Processing sketch that simulates an Asemic Writing. The technique is based on a sequence of eight random “words” that alternates randomly; each “word” is a combination of “elliptic oscillators” that follows the rectlinear movement of the (hidden) pen on the page.

The animation is accompained by a simple purely generative soundscape made with VCV Rack and Native Instruments Absynth VST.

This is the final result.

As soon as I clean-up a little bit the code (actually a mess) I’ll publish it here and add more details.



… The Ugliest Album: The Alien Ping

In a previous post (see here) I talked about “The world’s ugliest music”, a composition made by Scott Rickard using some math techniques in order to minimize the repetitions and the predictability of the sequence of notes. I also made my personal interpretation of the piece using a synthesizer and VCV Rack.

Then I launched a “challenge” on the VCV Community site asking VCV users to give their own interpretation of the ugliest music in an “sci-fi alien context” starting from the MIDI file or a small VCV template with the sequence. Many users accepted the challenge and created very interesting patches (and accompaining videos) … surely if put together they well represent THE UGLIEST ALBUM: The Alien Ping.

Continue reading

The Ugliest Music on Synthesizer

Recently I saw a TEDx video by Scott Rickard about “The world’s ugliest music”; and I suggest you to watch it.
Usually good music is characterized by a balance between repetition and variation, applied to one or many of the components of the music itself: melody, texture, rhythm, form, and harmony. So what happens if we try to completely remove the repetitions?

In Scott’s music a math formula is used to generate all the 88 notes of a piano and their duration: starting from value 1, the next value is generated multiplying by 3 the previous one. If the value exceeds 88 then 89 is repeatedly subtracted until the value falls back in the 1-88 range:

1, 3, 9, 27, 81, 243–>154–>65, 195–>106–>17, … and so on

Sequences of this type are known as Costas Arrays (or Costas permutations) ; they have been studied by John Costas during his search for ideal sonar waveforms (‘pings’).

The duration of the notes are calculated using a Golomb ruler : each note is placed on the timeline in a special position (“mark”) in order to avoid any recognizable rythmic pattern. Indeed in a Golomb ruler the positions of the marks are such that all distances between them are distinct. The sequence of 88 note durations (expressed in 1/16th)  used in the ugliest music is the following:

33, 3, 45, 10, 18, 47, 30, 311, 96, 46, 145, 37, 14, 17, 71, 22, 175, 132, 8, 66,
41, 251, 11, 50, 67, 59, 39, 23, 56, 34, 241, 2, 133, 35, 157, 204, 6, 108, 29,
57, 122, 52, 60, 89, 49, 85, 147, 218, 21, 32, 72, 44, 100, 19, 111, 16, 27,
178, 12, 181, 26, 38, 103, 99, 183, 20, 131, 78, 80, 4, 180, 15, 25, 212, 24,
286, 54, 9, 92, 5, 159, 7, 87, 42, 172, 13, 69, 1

You can listen to the music played on piano in the last part of the TEDx video; the title of the piece is “Costas Golomb N.1: The Perfect Ping” … and it is quite ugly. But I like creating “bleeps and bloops” on a modular synthesizer (actually I’m using VCV-Rack and a semimodular Behringer Neutron), and sometimes the results are often not really melodic … so I tried to make a patch and play the ugliest music on it.

I also made a simple sketch in Processing 3 in which the 88×88 grid (notes are from left-to-right, top-to-bottom) are displayed and a “sonar ping” is generated when each note is played.

If you want to experiment yourself you can download:

… and the Neutron patch:

Visual Meditation with Tibetan Singing Bowls

A Processing 3 sketch of four slowly evolving polygons and a meditative soundscape created by a few Tibetan Singing Bowls.

The algorithm is very simple:

  • place each vertex of each polygon in a random position
  • assign to each vertex a random direction (all polygons have the same scalar velocity)
  • at every frame move each vertex, if the new position is outside a border, simply make it bounce (reverse the velocity component orthogonal to the border)
  • assign a different color to each polygon and draw only its outer border (no fill)

The source code can be dowloaded here.

I made a video of the animation (starting from 4 rectangles) and added a soundscape made with sampled Tibetan Singing Bowls.

Other implementation ideas:

  • change the speed of each vertex
  • slowly change the color of each polygon
  • generate a MIDI message each time a vertex hits a border and send it to a virtual instrument or synth

If you improve the code or implement other variations let me know in the comments below.

Imitating Nature Ep.1 – The Cuckoo (sound synthesis)

This is the first post about “artisanal” sound synthesis techniques that can be used to imitate (try-to imitate 😉 ) the wonderful sounds of nature. I tried to replicate the chirping of cuckoos that in this period can be heard near my house (North Italy).

I started with a raw and noisy recording of one of them, made with the nice Tascam DR-40 recorder:

Note that the cuckoo is far away and it is barely audible in the recording.

I ampified the wav file using the free (and powerful) tool Audacity: CTRL+A to select all the sound; Effect→ Amplify , set new peak to -3dB. Then the cuckoo is audible (five chirps), though there are another bird chirping, a dog is barking and there are some noises from the road:

Continue reading

Conway’s Game of Life variations

This is a three-part post about Conway’s Game of Life and some easy-to-implement  variations that can lead to interesting visual results.

  • Part 1: adding colors
  • Part 2: extending the neighbourhood [… coming soon …]
  • Part 3: moving to the third dimension [… coming soon …]

Part 1: adding colors

The Conway’s Game of Life is a cellular automaton created by the British mathematician John Horton Conway in 1970. It is a theoretically infinite grid of cells; each cell can be in two states: dead ($0$) or alive ($1$). Initially the grid has a particular initial configuration  (for example a percentage of the cells are set to alive).  Then the cells evolve, and the state of cell $(x,y)$ at generation $N+1$ depends only on its state and the state of its eight neighbours at generation $N$. The rules are simple:

  • if a dead cell at generation $N$ is surrounded exactly by 3 alive cells then it willl be alive at generation $N+1$
  • if an alive cell at generation $N$ is surrounded by  2 or 3 alive cells, then it will stay alive, otherwise it will become a dead cell at generation $N+1$

Despite the simple rules, the Conway’s Game of Life is a Turing Complete model of computation (i.e. it can simulate any computer).

The visual configurations and the animations are also visually interesting.

A first variant can be obtained in the following way:

  • overlap three independent cell grids (one for each component Red-Green-Blue)
  • animate each grid using the standard rules, but for each cell $(x,y)$ in each grid also keep a fractional (float) value $C(x,y)$ in the range (0,1) ($C_r$ for the red grid, $C_g$ for the green grid, $C_b$ for the blue grid) and update it using the following rules:
    • if a cell becomes alive then add a fixed constant $v_1$ to it: $$C(x,y) = C(x,y)+v_1$$
    • if a cell becomes dead then subtract a fixed constant $v_0$ to it: $$C(x,y) = C(x,y) – v_0$$
  • render each cell $(x,y)$ with a square (or pixel) and color it according to the three RGB components values $C_r, C_g, C_b$ that it has in the three independent grids: $Red = C_r(x,y)*255$, $Green=C_g(x,y)*255$ , $Blue=C_b(x,y)*255$

This is a video that shows the resulting animation made with Processing 3 using $v_1=0.3$, $v_0=0.04$, starting from an initial random configuration:

The Processing source code can be downloaded here:



Cyclic Cellular Automata

A cyclic cellular automaton (CCA) is defined as an automaton where each cell takes one of N states 0, 1,…, N-1 and a cell in state i changes to state i+1 mod N at the next time step if it has a neighbor that is in state i+1 mod N, otherwise it remains in state i at the next time step. Classically CCA are applied on the 2-dimensional integer lattice with Von Neumann neighborhoods (nearest 4 neighbors): if cell is at coordinate (x,y), the four neighbours are those at coordinates (x+1,y), (x-1,y), (x,y+1), (x,y-1).

The cells are arranged in a bidimensional grid and initially they are in a random state. At each generation a cell in state i evolves to state i+1 mod N if at least one of its neighbors is in state i+1. The color of each cell is determined by its state.

The following image is generated using Von Neumann neighborhood:

Cyclic CA Von Neumann neighborhood

[click to enlarge]

But very interesting behaviors can also be obtained if we pick irregular/random neighborhoods.

Continue reading