Skip to content

Repository files navigation

Cellular Automata for Processing

This library allows you to make art in Processing using cellular automata. See Conway's Game of Life for an example of a well known cellular automaton.

Get Started

  1. Install Processing
  2. Download the latest automata.zip
  3. Extract the zip file to the "libraries" sub-folder of your Processing documents folder
  4. Launch Processing, go to File → Examples, and browse the Cellular Automata examples

Usage

// Import the library
import com.grough.automata.*;

// Create your own animation by extending the base class.
// Choose a data type for your cells. In this case we use Boolean.
class MyAnimation extends Automaton<Boolean> {

  // Populate the initial cell values.
  Boolean populate() {
    return random(0, 1) < 0.5;
  }

  // Calculate the next cell value based on the previous cell value.
  Boolean evolve() {
    if (random(0, 1) < 0.1) {
      return self();
    } else {
      return !self();
    }
  }

  // Assign the cell a color based on its value.
  int shade() {
    return self() ? 0 : 255;
  }
}

MyAnimation animation = new MyAnimation();

void setup() {
  size(640, 640);
}

void draw() {
  // Advance to the next animation frame each time we draw.
  animation.next();

  // Draw the animation's graphics on the screen.
  image(animation.graphics(), 0, 0, 640, 640);
}

About

Cellular automata for Processing

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages