Overview
Flow Field is a canvas-based particle animation component that simulates thousands of particles flowing through an organic noise field. The particles leave luminous trails creating a mesmerizing, ever-evolving visual effect perfect for hero sections and backgrounds.Installation
- Tab Title
- Tab Title
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the container |
children | ReactNode | Default hero content | Custom content to display over the animation |
theme | "aurora" | "ember" | "ocean" | "aurora" | Color theme for the particles |
density | "sparse" | "medium" | "dense" | "medium" | Number of particles (600/1200/2000) |
Usage
Basic Usage
With Different Themes
With Different Densities
Custom Content
Color Themes
Aurora (Default)
- Hue Range: 120-320 (green → blue → purple)
- Background: Very dark blue-gray (5, 5, 8)
- Saturation: 90%
- Lightness: 62%
- Effect: Ethereal, northern-lights inspired
Ember
- Hue Range: 0-55 (red → orange → yellow)
- Background: Very dark brown (8, 4, 2)
- Saturation: 95%
- Lightness: 58%
- Effect: Warm, fire-like glow
Ocean
- Hue Range: 180-270 (cyan → blue)
- Background: Very dark blue (2, 6, 10)
- Saturation: 88%
- Lightness: 60%
- Effect: Cool, underwater atmosphere
Particle Densities
| Density | Particles | Use Case |
|---|---|---|
sparse | 600 | Subtle effect, better performance, minimal distraction |
medium | 1200 | Balanced effect, good performance (default) |
dense | 2000 | Dramatic effect, more visual impact, higher GPU usage |
Features
- Noise-Driven Motion: Particles follow an organic vector field based on multi-octave trigonometric noise
- Luminous Trails: Each particle leaves a glowing trail that fades over time
- Color Shifting: Particle colors shift based on flow direction for variety
- Lifecycle Fading: Particles fade in and out smoothly during their lifetime
- Edge Wrapping: Particles wrap around screen edges for seamless animation
- Responsive: Automatically adapts to window size with device pixel ratio support
- Performance Optimized: Efficient canvas rendering with requestAnimationFrame
- Three Themes: Aurora, Ember, and Ocean color schemes
- Vignette Effect: Radial gradient overlay focuses attention on center content
How It Works
Noise Field
ThefieldAngle function generates a continuously evolving 2D noise field:
Particle Behavior
- Spawn: Particles start at random positions with random lifespans (200-500 frames)
- Flow: Each frame, particles query the noise field and move in that direction
- Fade: Particles fade in over first 12.5% of life, fade out over last 16%
- Respawn: When a particle’s life expires, it respawns at a new random location
- Trail: Canvas fade effect creates trailing effect behind each particle
Rendering Pipeline
- Apply semi-transparent overlay (fades previous frame by ~6-7%)
- For each particle:
- Calculate flow field angle at particle position
- Update position based on angle and speed
- Calculate fade-in/fade-out alpha
- Shift hue based on flow direction
- Draw particle as small circle (1.3px radius)
- Request next animation frame
Customization
Creating Custom Themes
You can modify theTHEMES constant in the source to add custom color schemes:
Adjusting Particle Count
Modify thePARTICLE_COUNTS constant:
Tuning the Flow Field
In thefieldAngle function, adjust:
Performance Considerations
- Canvas Size: Uses
devicePixelRatiofor sharp rendering on high-DPI displays - Frame Rate: Runs at ~60fps via
requestAnimationFrame - Memory: Particle array is reused, not recreated each frame
- GPU: Canvas rendering is hardware-accelerated in modern browsers
- Density Impact: Dense mode (2000 particles) uses ~3x CPU/GPU vs sparse mode
Performance Tips
- Use
sparsedensity on mobile devices - Use
mediumordenseon desktop with good GPUs - Consider reducing particle count for lower-end devices
- The component automatically cleans up on unmount
Dependencies
motion(Framer Motion) - For content fade-in animationsreact- Core hooks (useEffect, useRef)cnutility - For className merging (from shadcn/ui)
Accessibility
- Canvas is marked with
aria-hidden="true"(decorative only) - Vignette overlays are also
aria-hidden - Ensure custom content has proper semantic structure
- Component respects
prefers-reduced-motionthrough Framer Motion
Browser Support
Works in all modern browsers that support:- HTML Canvas 2D Context
- requestAnimationFrame
- CSS radial/linear gradients
- ES6+ JavaScript (arrow functions, const/let, template literals)