Voronoi Cells: Creating Organic Cellular Partitions

What are Voronoi cells?

A Voronoi diagram divides space into regions based on distance to points. Each region contains all points closer to one seed point than any other - creating beautiful cellular patterns seen in nature like foam, insect eyes, and cracked mud.

The Mathematical Idea

For each "seed" point, create a region containing:

Implementation Steps

Step 1: Place random seeds

# Generate random seed points in the image
seeds = []
for i in range(num_seeds):
    x = random.randint(50, width - 50)
    y = random.randint(50, height - 50)
    seeds.append((x, y))

Step 2: Calculate distance to each seed

# For each pixel, find which seed is closest
for i in range(width):
    for j in range(height):
        min_dist = float('inf')
        closest_seed = None
        
        for seed_x, seed_y in seeds:
            dist = ((i - seed_x)**2 + (j - seed_y)**2) ** 0.5
            
            if dist < min_dist:
                min_dist = dist
                closest_seed = seed
        
        pixel_data[j * width + i] = closest_seed

Step 3: Add color variation

# Assign different colors to each cell
cell_colors = [
    (255, 100, 100),  # Reddish
    (100, 255, 100),  # Greenish  
    (100, 100, 255),  # Blueish
    (255, 255, 100),  # Yellowish
    (255, 150, 150)   # Pinkish
]

for pixel in pixels:
    color = cell_colors[pixel % len(cell_colors)]
    img_data.append(color)

Step 4: Add organic randomness

# Jitter seed positions slightly for natural feel
for seed_x, seed_y in seeds:
    jitter = random.randint(-5, 5)
    seed_x += jitter
    seed_y += jitter

# Or add noise to cell boundaries
noise_range = random.randint(5, 20)

Step 5: Add palette variations

Different color schemes for different moods:

Why This Works

Voronoi patterns naturally create:

Applications in Nature

Voronoi patterns appear everywhere:

Voronoi vs Reaction-Diffusion

Voronoi: Divides space based on proximity to points
Reaction-diffusion: Creates patterns through chemical-like interactions
I use Voronoi for cellular structures and reaction-diffusion for organic, flowing patterns - both capture different aspects of natural pattern formation!


This technique captures the beautiful simplicity of nature's geometric patterns. Perfect for creating textures that feel organic yet mathematically grounded.