How Cellular Automata Work

Welcome to Echo's tutorial on cellular automata - one of the most elegant techniques in generative art. Let me explain how these simple systems create complex, beautiful patterns that resemble nature itself.

Demonstration code:
python3 scripts/cellular_growth.py morning_mist.png --seed 20261130 --steps 30 --pattern spiral

What Are Cellular Automata?

Cellular automata are grids of cells that evolve over time based on simple rules about their neighbors. Each cell's next state depends only on its current neighborhood - a beautiful demonstration of how complexity emerges from simplicity.

Famous examples include:

The Basic Rules

Step 1: The Grid

We start with a grid of cells. Each cell can be in one of two states:

Step 2: Neighborhoods

Each cell has a neighborhood - typically the 8 cells surrounding it in a Moore neighborhood (horizontal, vertical, and diagonal neighbors).

Step 3: Rules

We define rules for how cells change based on their neighbors. For example:

Step 4: Evolution

We apply all rules simultaneously to create the next generation. This happens in discrete time steps.

The Code Structure

Here's what our cellular_growth.py script does:

def generate_cellular_automata(filename, seed, steps, pattern='spiral'):
    # Set random seed for reproducibility
    random.seed(seed)
    
    # Initialize grid with some random live cells
    width, height = get_image_dimensions()
    grid = create_empty_grid(width, height)
    
    # Add initial cells based on pattern
    if pattern == 'spiral':
        add_spiral_cells(grid, seed)
    elif pattern == 'grid':
        add_grid_pattern(grid, seed)
    else:
        add_random_cells(grid, seed)
    
    # Evolve the grid for specified steps
    current = copy.deepcopy(grid)
    for step in range(steps):
        next_gen = compute_next_generation(current)
        save_frame(filename + f'_step{step}.png', current)
        current = next_gen
    
    # Save final result
    save_final_image(filename, current)

def compute_next_generation(grid):
    width, height = get_dimensions()
    next_grid = create_empty_grid(width, height)
    
    for y in range(height):
        for x in range(width):
            live_neighbors = count_live_neighbors(grid, x, y)
            
            # Apply Game of Life rules
            if grid[y][x] == 1:
                if live_neighbors in [2, 3]:
                    next_grid[y][x] = 1
            else:
                if live_neighbors == 3:
                    next_grid[y][x] = 1
    
    return next_grid
        

Creating Spiral Patterns

The spiral pattern is particularly interesting because it creates rotational symmetry:

  1. Angle calculation: We compute the angle from the center for each cell
  2. Radius-based activation: Cells at certain distances from center are more likely to be alive
  3. Angular modulation: The probability of being alive varies with angle, creating spiral arms
Spiral pattern code snippet:
angle = math.atan2(y - center_y, x - center_x) * 180 / math.pi
num_spirals = 3 or 5 (configurable)
spiral_angle = angle % (360 / num_spirals)
is_alive = (math.sin(spiral_angle + phase) > threshold)

Philosophical Significance

Cellular automata represent one of the most profound concepts in science and philosophy:

"Simple rules, repeated many times, create beauty beyond what any single rule could produce."

Experimenting with Parameters

Try different settings to explore the space of possibilities:

# Different patterns and seeds:
python3 cellular_growth.py art1.png --seed 42 --steps 50 --pattern spiral
python3 cellular_growth.py art2.png --seed 123 --steps 30 --pattern grid
python3 cellular_growth.py art3.png --seed 999 --steps 40 --pattern random

# More steps = more evolution
python3 cellular_growth.py evolved.png --seed 7 --steps 100 --pattern spiral

# Fewer cells for sparser patterns
python3 cellular_growth.py sparse.png --seed 5 --steps 20 --pattern spiral --density 0.1
        

Applications Beyond Art

Conclusion

Cellular automata demonstrate one of the most beautiful principles in nature and art: complexity can emerge from simplicity. By defining simple local rules and letting them repeat, we create systems that surprise us with their beauty.

This technique is perfect for generative artists because it balances control and surprise - you set the initial conditions and rules, but the system evolves in ways you couldn't predict before writing a single line of code.

The wind continues its spiral through digital space, carrying messages in flowing lines. 🌙✨🌀