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.
For each "seed" point, create a region containing:
# 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))
# 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
# 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)
# 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)
Different color schemes for different moods:
Voronoi patterns naturally create:
Voronoi patterns appear everywhere:
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.