2 patterns-animation-Perlin-Noise-Fractal
Balazs Horvath edited this page 2026-04-18 11:13:08 +02:00

Perlin Noise Fractal

Torch-based Perlin-like noise with varying Gaussian filter for smooth transitions.

Mathematical Formula


\text{noise} = \text{rand}(H, W, 3) \\
\sigma(t) = 5 + 10 \cdot \sin(t/10) \\
\text{smooth\_noise} = \text{gaussian\_filter}(\text{noise}, \sigma(t))

Where:

  • Random noise smoothed by Gaussian filter
  • Sigma varies with time for dynamic effect

How It Works

Perlin noise creates smooth, organic-looking patterns by smoothing random noise with a Gaussian filter. Varying the filter's sigma over time creates dynamic transitions between different detail levels.

Implementation

import torch
from scipy.ndimage import gaussian_filter
import numpy as np

# Generate Perlin-like noise animation
width, height = 512, 512
frames = []

for t in range(30):
    # Base noise
    noise = torch.rand(height, width, 3).numpy()
    
    # Apply Gaussian filter with varying sigma for smooth transitions
    sigma = 5 + 10 * np.sin(t / 10)
    smooth_noise = gaussian_filter(noise, sigma=sigma)
    
    # Convert to tensor
    smooth_noise = torch.from_numpy(smooth_noise).float()
    frames.append(smooth_noise)

output_image = torch.stack(frames, dim=0)  # Shape: [30, H, W, 3]

Line-by-Line Explanation

noise = torch.rand(height, width, 3).numpy()

Generates random noise in [0, 1] range.

sigma = 5 + 10 * np.sin(t / 10)

Sigma oscillates between 5 and 15 over time.

smooth_noise = gaussian_filter(noise, sigma=sigma)

Smooths noise with varying blur amount.

Customization

Constant Sigma

sigma = 10  # Fixed blur

Larger Range

sigma = 2 + 20 * np.sin(t / 10)  # 2 to 22

Different Frequency

sigma = 5 + 10 * np.sin(t / 5)  # Faster variation

References