Cellular Automata Generator

A Processing tool for generating images and videos based on Cellular Automata concept. Change rules and colour palettes on the go, add your images, use brushes and share the results with other sketches or applications via Syphon. Sync to music for live performances!

Download the app (MacOSX, Windows)
Download source (pde)
How does it work?

note: the code is open source, which means that you can use it freely with a proper credit. If you are interested in a commercial use, contact me.

Idea

My interest in CA (Cellular Automata) began the day I accidentaly hit the CelLab website. Until then the only CA I knew was Conway’s Game of Life. CelLab project amazed me with its features – a list of different rules and colour palettes. I desperately wanted to work with it on my own terms and build a tool.

My basic goals were:

  • to keep the idea of a list of rules and colour palettes
  • to change settings (rules/colour palettes) as easily as possible (with one mouse click or a keyboard shortcut) and without a need to restart the program
  • to add images during calculations (not only as a basic state)
  • to draw your own pictures (simple mouse painter)
  • to capture the results as a video or a screenshot
  • to easily share the results live with other programs or sketches (Syphon)
  • make it useful in VJ-ing (make automatic changes synced to specific tempo or midi clock)

It took me months to finally get to the point I feel I can share the result.

About CA

In brief: the idea of CA is to generate an array of states (pixels of an image) from another array of states using a specific function (a rule). The new array is called a next generation and is simply a next video frame. If you generate the frames constantly you will get an animation.

Conway’s Game of Life

Conway’s Game of Life

A rule applies to every pixel of an image and usually depends on other pixels from a previous frame. The most popular CA rule is called Game of Life, a 2D binary array in which every pixels depends on its closest neighbours. In every frame and for every pixel you read its current state (0/1 or dead/alive), then count its alive neighbours (0-8) and due to the rule below you get a new state:

Conway’s Game of Life Rules

newState = currentState; if (currentState == 1) { if (neighbours < 2 || neighbours > 3) { newState = 0; } } else { if (neighbours == 3) { newState = 1; } }

Game of Life is just one of CA rules. CA can work with other range of states (ie. 256 values of gray) and in 1D arrays, 2D or 3D, or whatever you want. You can find some cool 3D examples in the web. It also doesn’t necessarily have to be squares. Anyway, I decided to work with 2D 256-states array, which fits a grayscale animation.

Run the project

If you downloaded the sketch, to run a project you also need to have Syphon and oscP5 libraries installed. They are easy to find in Processing menu. If you do, the sketch should run right away without any issues.

This is what the interface should look like:

CA Interface

The left square contains a preview of a current frame. If you turn on Syphon in the main Tab, this is what is sent to other programs or sketches.

Next, you find lists for Rules, Palettes, Images, Brushes, Generate functions and Settings. All of these are available under keyboard shortcuts. You move between parts by pressing 1-5 nums. Each option has a shortcut printed close to its name.

Rules

The rules I developed in my project are quite simple and I only take them as examples. I encourage you to make up and write your own conditions.

The most common function I use to generate next frame is checkState(int x, int y, int xTranspose, int yTranspose). With it I always deliver values of 8 closest neighbours: nn, ne, ee, se, ss, sw, ww, nw. The rule always result with newState value.



Let’s take Plasma Rule as another example. Here, for every pixel I copy the value of one of the pixels around [nn, ne, ee, se, ss, sw, ww, nw] depending on noise(x,y) function:

CA Plasma

CA Plasma Rule

In Expand Rule I set every black pixel to the brightness value of a random neighbour and decrease this value by 5:

CA Expand

CA Expand Rule

Some of the rules are dedicated especially for drawing, like the White Shadow rule.

CA White Shadow

CA White Shadow

Sometimes you don’t even need to think of the neighbours. Simply increase the newState value every frame to get a Blink effect:

CA Blink

CA Blink Rule

Palettes

Every rule in this project operates on 256 states (256 shades of gray), which means that Grayscale is a basic colour scheme. I wanted to make the visual result look fancier and more diverse, so I added colour mapping (often called Gradient Map). The idea behind it is to change every of 0-255 grays due to a specific colour preset (Palette).

CA Palettes examples

CA Palettes examples

Creating new palette is simple and you can find different approaches to do this in the code. You have to fill an array named colour paletteStopsList[256] with as many colour stops as you like. Basically it automatically fills the gaps with gradients. You can use noGradients() at the beginning to prevent it. Also, you can make a palette build randomly, like I did to few of my palettes.

Images

You can insert an image from the sketch library in any moment you want. If you’d like to use your own images, simply copy your files to /data/images/ directory and add them in OP_IMAGES tab. The project will apply a greyscale filter and convert pure black to transparent by default.

CA Images

CA Images

Brushes

Drawing is another way to interact live with the screen. You can find 4 brushes at your disposal: rectangle, line, smooth or spray.

CA Rectangle Brush

CA Rectangle Brush

Glitches

I also added few "generative" effects possible to apply:

  • Contra – inverts a random part of the frame
  • Noise – changes every pixel to a random value
  • Snow – adds few white pixels in random places
  • Glitch – copies a random part of the frame and pastes in a random place
  • Flatten – changes a random part of gradient colours to a solid colour
CA Glitch

CA Glitch

Settings

The last part of the interface includes settings. Here, you can:

  • pick a display size in a range from 8x8 to 512x512
  • start/pause the rule
  • clear screen
  • turn on the Automator (described below)
  • turn on recording – frames are saved to /movies/ directory
  • save screen as .tif file /screenshots/ directory
  • copy/paste the current frame to clipboard
  • pick a new array of Perlin noise (used in Perlin rule)

Sync to music (Automator)

If you’d like to use all these features for a visual performance synced to music, then I recommend downloading Automator extension. This is a small Processing sketch I wrote, which captures your mouse clicks and keyboard presses, put them on a timeline and repeatedly send back. It works like a looper for your actions – it changes rules, palettes, add images, etc. In the rhythm you program it to. Sketch requires OscP5 communication (one of basic libraries). All you have to do is run both Automator and CA sketches, then turn the Automation on in CA.

Automator

Automator

What next?

If you have any idea how to improve this tool or simply would like to help developing it, then I’m more than happy to cooperate. If you got any problems using it or find a bug, also please let me know. Enjoy!