2 patterns-animation-Plasma-Effect
Balazs Horvath edited this page 2026-04-18 11:13:06 +02:00

Plasma Effect

Torch-based plasma effect with color cycling, demonstrating sine wave superposition.

Mathematical Formula


P(x, y, t) = \frac{\sin(x + \omega_1 t) + \sin(y + \omega_2 t) + \sin(\frac{x+y}{2} + \omega_3 t)}{3}

Where:

  • \omega_1, \omega_2, \omega_3 are temporal frequencies
  • Three sine waves create interference pattern
  • Color cycling with phase shifts

How It Works

Plasma effects demonstrate wave superposition. Multiple sine waves with different orientations combine to create complex, flowing patterns. Color cycling adds time-based color shifts.

Implementation

import torch

# Generate plasma effect frames
width, height = 512, 512
frames = []

for t in range(30):
    x = torch.linspace(0, 2*torch.pi, width)
    y = torch.linspace(0, 2*torch.pi, height)
    X, Y = torch.meshgrid(x, y, indexing='ij')
    
    # Plasma formula with time variation
    plasma = torch.sin(X + t/5) + torch.sin(Y + t/5) + torch.sin((X+Y)/2 + t/5)
    plasma = (plasma + 3) / 6  # Normalize to 0-1
    
    # Convert to RGB with color cycling
    r = torch.sin(plasma * torch.pi + t/10)
    g = torch.sin(plasma * torch.pi + t/10 + 2*torch.pi/3)
    b = torch.sin(plasma * torch.pi + t/10 + 4*torch.pi/3)
    
    rgb = torch.stack([r, g, b], dim=-1)
    rgb = ((rgb + 1) / 2)  # Normalize to 0-1
    frames.append(rgb)

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

Line-by-Line Explanation

plasma = torch.sin(X + t/5) + torch.sin(Y + t/5) + torch.sin((X+Y)/2 + t/5)

Three sine waves: horizontal, vertical, and diagonal.

plasma = (plasma + 3) / 6

Normalizes from [-3, 3] to [0, 1].

r = torch.sin(plasma * torch.pi + t/10)

Maps plasma value to red with time variation.

Customization

More Waves

plasma = (torch.sin(X + t/5) + torch.sin(Y + t/5) + 
          torch.sin((X+Y)/2 + t/5) + torch.sin((X-Y)/2 + t/5)) / 4

Different Speed

plasma = torch.sin(X + t/10) + torch.sin(Y + t/10)  # Slower

References