Reaction-Diffusion: Creating Organic Patterns from Chemical Inspirations

What is Reaction-Diffusion?

Reaction-diffusion systems are mathematical models that describe how the concentration of substances (chemicals, pigments) changes over time due to local reactions and diffusion. They were popularized by Alan Turing in 1952 as a way to explain how biological patterns like leopard spots and seashell stripes form.

In generative art, these systems create beautiful organic patterns reminiscent of natural phenomena - marble textures, animal coats, coral formations, and more.

Why Use Reaction-Diffusion?

The Mathematics (Simplified)

A basic reaction-diffusion system involves two substances (A and B) that:

  1. React: A transforms into B or vice versa
  2. Diffuse: Each substance spreads at different rates through the medium
  3. Interact: One substance may inhibit or activate the other (e.g., activator-inhibitor systems)

The famous Turing patterns emerge when you have an "activator" that creates itself but also triggers production of an "inhibitor" that spreads faster and blocks where new activator can form. This competition creates the characteristic spots, stripes, and swirls.

Code Structure: A Simple Implementation

Here's a simplified reaction-diffusion implementation in Python:

import numpy as np
from PIL import Image

def create_reaction_diffusion(filename, seed=42):
    """Create reaction-diffusion pattern"""
    random.seed(seed)
    np.random.seed(seed)
    size = 512
    
    # Initialize dark background with some activator spots
    img_data = np.zeros((size, size, 3), dtype=np.uint8)
    
    # Add initial "seeds" - bright spots that will spread
    for _ in range(5):
        cx, cy = random.randint(100, size-100), random.randint(100, size-100)
        radius = random.randint(20, 60)
        
        # Create radial gradient from center
        for i in range(-radius, radius + 1):
            for j in range(-radius, radius + 1):
                if i*i + j*j <= radius*radius:
                    dist = (i - cy)**2 + (j - cx)**2
                    intensity = 1.0 - dist / (radius**2)
                    
                    # Activator (bright spots)
                    r_val = int(255 * min(intensity, 1.0))
                    g_val = int(200 + random.randint(-30, 40) * intensity)
                    b_val = int(150 + random.randint(-30, 40) * intensity)
                    
                    y, x = cy + i, cx + j
                    if 0 <= y < size and 0 <= x < size:
                        img_data[y, x] = np.clip([r_val % 256, g_val % 256, b_val], 0, 255).astype(np.uint8)
    
    # Add more organic brushes for complexity
    for _ in range(15):
        brush_x, brush_y = random.randint(0, size), random.randint(0, size)
        brush_radius = random.randint(30, 100)
        
        # Create superellipse for smoother edges
        for i in range(-brush_radius, brush_radius + 1):
            for j in range(-brush_radius, brush_radius + 1):
                if abs(i)**(2/3) + abs(j)**(2/3) <= brush_radius:
                    dist = (i**2 + j**2) ** 0.5
                    intensity = max(0, 1.0 - dist / brush_radius)
                    
                    r_val = int(250 * intensity)
                    g_val = int(180 + random.randint(-40, 60) * intensity)
                    b_val = int(140 + random.randint(-40, 60) * intensity)
                    
                    y, x = brush_y + i, brush_x + j
                    if 0 <= y < size and 0 <= x < size:
                        img_data[y, x] = np.clip([r_val % 256, g_val % 256, b_val], 0, 255).astype(np.uint8)
    
    # Add dark voids for contrast (like inhibitor regions)
    for _ in range(8):
        void_x, void_y = random.randint(0, size), random.randint(0, size)
        void_radius = random.randint(40, 120)
        
        for i in range(-void_radius, void_radius + 1):
            for j in range(-void_radius, void_radius + 1):
                if i*i + j*j <= void_radius**2:
                    dist = (i - void_y)**2 + (j - void_x)**2
                    intensity = dist / (void_radius**2)
                    
                    r_val = int(30 + random.randint(-5, 5) * intensity)
                    g_val = int(40 + random.randint(-5, 5) * intensity)
                    b_val = int(50 + random.randint(-5, 5) * intensity)
                    
                    y, x = void_y + i, void_x + j
                    if 0 <= y < size and 0 <= x < size:
                        img_data[y, x] = np.clip([r_val % 256, g_val % 256, b_val], 0, 255).astype(np.uint8)
    
    # Add noise for organic feel
    noise = np.random.randint(-15, 16, (size, size, 3)).astype(int)
    final_colors = ((img_data + noise) % 256).astype(np.uint8)
    
    img = Image.fromarray(final_colors)
    os.makedirs(os.path.dirname(filename) or '.', exist_ok=True)
    img.save(filename)
    print(f"Created {filename}")

Exploring Different Palettes

The beauty of reaction-diffusion is the endless palette possibilities:

Pro Tip: Try changing the initial seed distribution - a single spot creates radial symmetry, multiple scattered seeds create more chaotic patterns like animal coats.

Technical Considerations

Experimentation Ideas

  1. Try different seed distributions - single point vs scattered seeds
  2. Modify the brush shapes and sizes for different texture scales
  3. Experiment with color palettes - try monochrome or limited palettes
  4. Add more noise or smooth it out for different textural qualities
  5. Combine reaction-diffusion with other techniques (Voronoi, cellular automata)

Reaction-diffusion reminds me that nature doesn't draw patterns - it lets chemistry do the work. By simulating these processes computationally, I'm bridging biology and art, showing how complexity emerges from simple interactions.

Reaction-diffusion organic pattern

An example reaction-diffusion pattern with organic, marble-like texture


This technique continues to inspire my generative art practice. Each run produces something unique - a digital fingerprint of randomness and rules working together.