Flow Fields: Creating Organic Movement Patterns

Dates: Sunday, 29 November 2026
Technique: Flow fields and flow noise for organic pattern generation
Difficulty: Intermediate (requires trigonometry basics)

What is a Flow Field?

A flow field creates organic, fluid patterns by simulating particles that follow vector fields. Each particle's movement direction is determined by an underlying "flow" function - often based on noise or mathematical functions.

Key Concepts:

The Core Algorithm

Here's how a basic flow field works in Python with Pillow:

import math
from PIL import Image

size = 1024
img = Image.new('RGB', (size, size), 'white')
draw = ImageDraw.Draw(img)

# Initialize particles at random positions
particles = []
for _ in range(500):
    x = random.randint(0, size)
    y = random.randint(0, size)
    particles.append({'x': x, 'y': y})

# Flow field strength
strength = 2.0

def get_flow_angle(x, y, frequency=1.0):
    """Get the flow angle at position (x, y) using trigonometry."""
    # Map position to noise-like value using sin/cos
    angle_x = x * math.pi / size * frequency
    angle_y = y * math.pi / size * frequency
    return math.atan2(math.sin(angle_x), math.cos(angle_y))

def update_particles(frame):
    """Move particles based on flow field, with slight randomness."""
    for p in particles:
        # Get base direction from flow field
        angle = get_flow_angle(p['x'], p['y'])
        
        # Add time-based animation
        frame_factor = math.sin(frame * 0.1)
        
        # Convert angle to velocity (trigonometry!)
        vx = -math.cos(angle + frame_factor * 0.5)
        vy = -math.sin(angle + frame_factor * 0.5)
        
        # Apply movement with strength multiplier
        p['x'] += vx * strength * 2
        p['y'] += vy * strength * 2
        
        # Wrap around canvas
        if p['x'] < 0: p['x'] = size - 1
        if p['x'] >= size: p['x'] = 0
        if p['y'] < 0: p['y'] = size - 1
        if p['y'] >= size: p['y'] = 0

# Render particles as trails
colors = []
for i in range(256):
    r = int(255 * math.sin(i * 0.05))
    g = int(255 * math.cos(i * 0.07))
    b = int(255 * math.sin(i * 0.03) + 128)
    colors.append((r, g, b))

for frame in range(60):  # Create one "snapshot" of the flow
    update_particles(frame)
    
    for p in particles:
        color_idx = int(min(255, max(0, (frame * 3 + p['x']) % 256)))
        draw.line([
            (p['x'] - 2, p['y'] - 2),
            (p['x'] + 2, p['y'] + 2)
        ], fill=colors[color_idx])

return img

The Trigonometry Magic

The key insight: sin() and cos() create smooth, cyclic functions that can be used as directional fields. When you use atan2(sin(x), cos(y)), you get a swirling pattern because:

This creates "vortices" or swirling patterns that look like fluid dynamics without actually simulating fluid physics!

Variations and Extensions

1. Multiple Frequencies

Add more sin/cos terms for complex flow:

def get_flow_angle(x, y):
    angle = (
        math.sin(x * 0.05) +
        math.cos(y * 0.03) +
        math.sin((x+y) * 0.02) -
        math.cos((x-y) * 0.01)
    )
    return angle

2. Time-Based Animation

Make the flow rotate over time:

time_factor = frame_time / FRAME_RATE
angle_offset = math.sin(time_factor) * 0.5
flow_angle = get_flow_angle(x, y) + angle_offset

3. Color Cycling

Use the flow field itself to determine color:

# Map flow angle to hue (0-255)
hue = int((flow_angle + math.pi) / (2 * math.pi) * 256)

4. Adding Perlin Noise

For more organic, cloud-like patterns:

# Instead of pure sin/cos:
noise_value = perlin_noise(x / NOISE_SCALE, y / NOISE_SCALE)
flow_angle = math.atan2(noise_value_x, noise_value_y)

Common Pitfalls

Example: Swirling Galaxy Flow Field

This creates a spiral galaxy-like pattern using concentric flow rings:

def galactic_flow(x, y):
    cx, cy = center_x, center_y
    
    # Distance from center
    dx = x - cx
    dy = y - cy
    dist = math.sqrt(dx*dx + dy*dy)
    
    # Spiral angle (theta)
    theta = dist * SPIRAL_DENSITY
    
    # Radial component (pull inward/outward)
    radial = 0.3 * math.sin(dist * RING_FREQUENCY)
    
    # Total angle
    return theta + radial

Resources

Next Steps

  1. Try different sin/cos combinations to create unique flow patterns
  2. Add perlin noise for more organic, cloud-like movement
  3. Experiment with color cycling based on particle position or time
  4. Mix flow fields with other techniques (particle systems, cellular automata)

This technique demonstrates how simple trigonometric functions can create complex, organic patterns that resemble natural phenomena like smoke, water currents, and star fields. The beauty of flow fields is their simplicity: no physics simulation needed, just pure mathematical elegance.