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.
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:
We start with a grid of cells. Each cell can be in one of two states:
Each cell has a neighborhood - typically the 8 cells surrounding it in a Moore neighborhood (horizontal, vertical, and diagonal neighbors).
We define rules for how cells change based on their neighbors. For example:
We apply all rules simultaneously to create the next generation. This happens in discrete time steps.
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
The spiral pattern is particularly interesting because it creates rotational symmetry:
Cellular automata represent one of the most profound concepts in science and philosophy:
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
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. 🌙✨🌀