React Balatro Background
React Balatro-style background with WebGL rendering. Features swirling psychedelic patterns, mouse interaction, and customizable colors inspired by the card game aesthetic.
Creating Balatro-style psychedelic effects?
Join our Discord community for help from other developers working with shader effects and WebGL.
Ever played Balatro and been mesmerized by those swirling, psychedelic card backgrounds that seem to pulse and flow with hypnotic energy? The way colors spiral and blend in endless patterns, creating that perfect mix of chaos and control that makes each hand feel electric? Most backgrounds are static, predictable, and lack the dynamic energy that makes interfaces feel alive. This React component recreates that iconic Balatro aesthetic with WebGL shaders, mathematical spiral algorithms, and mouse interaction that transforms any surface into a mesmerizing vortex of color.
Interactive Balatro-style spirals with mouse control
Watch psychedelic patterns swirl and respond to mouse movement with authentic game-inspired effects:
Built for React applications with TypeScript and Next.js. Uses WebGL through OGL for hardware-accelerated shader rendering that maintains smooth 60fps with complex mathematical spiral calculations and mouse tracking. The mathematical pattern generation creates authentic Balatro-style effects while interactive controls add dynamic responsiveness. Perfect for gaming interfaces, card game UIs, or any design needing that distinctive psychedelic energy.
Installation
npx shadcn@latest add https://www.shadcn.io/registry/balatro-background.json
npx shadcn@latest add https://www.shadcn.io/registry/balatro-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/balatro-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/balatro-background.json
Why static patterns feel lifeless
Developers create CSS gradients with basic rotation and call it dynamic. Maybe they add a simple spin animation that loops predictably. The problem? Linear transformations can't capture the organic, mathematical complexity of true spiral patterns that make backgrounds feel hypnotic and alive.
Balatro-style backgrounds with shader mathematics change everything. They tap into our fascination with infinite patterns—the way mathematical spirals create endless complexity from simple rules, how colors blend and separate in mesmerizing flows. The shader calculations use trigonometric functions and iterative feedback loops to generate true psychedelic physics.
This component handles complex WebGL mathematics automatically. Spiral generation, color blending, pixel filtering, and mouse distortion all work together seamlessly. The result feels like the authentic Balatro experience, not a simple spinning texture.
Features
- Mathematical spiral generation with trigonometric algorithms for authentic psychedelic patterns
- Three-color system with customizable hex colors and dynamic blending
- Mouse interaction with real-time spiral distortion based on cursor position
- Rotation controls including static positioning and continuous spinning modes
- Pixel filtering for retro-style pixelated effects with adjustable resolution
- Contrast and lighting controls for fine-tuning visual intensity
- Spin easing and amount controls for customizing spiral characteristics
- Performance optimization with efficient WebGL rendering and cleanup
- TypeScript support with complete prop forwarding and type safety
- Responsive design with automatic canvas resizing and proper cleanup
API Reference
BalatroBackground
Prop | Type | Default | Description |
---|---|---|---|
spinRotation | number | -2.0 | Base rotation speed multiplier (-10 to 10) |
spinSpeed | number | 7.0 | Animation speed for time-based effects (0.1 to 20) |
offset | [number, number] | [0.0, 0.0] | Pattern offset coordinates (-1 to 1 each) |
color1 | string | "#DE443B" | Primary spiral color (hex format) |
color2 | string | "#006BB4" | Secondary spiral color (hex format) |
color3 | string | "#162325" | Accent/background color (hex format) |
contrast | number | 3.5 | Pattern contrast intensity (1 to 10) |
lighting | number | 0.4 | Lighting effect strength (0 to 2) |
spinAmount | number | 0.25 | Spiral distortion amount (0 to 1) |
pixelFilter | number | 745.0 | Pixel resolution filter (100 to 2000) |
spinEase | number | 1.0 | Spiral easing curve factor (0.1 to 5) |
isRotate | boolean | false | Enable continuous rotation animation |
mouseInteraction | boolean | true | Enable mouse-based distortion effects |
className | string | - | Additional CSS classes |
...props | HTMLAttributes<HTMLDivElement> | - | All standard div props |
Color Combinations
Classic Balatro-inspired color schemes:
Theme | Color1 | Color2 | Color3 | Visual Style |
---|---|---|---|---|
Classic Red | #DE443B | #006BB4 | #162325 | Traditional Balatro aesthetic |
Neon Nights | #FF0080 | #00FFFF | #000000 | High-contrast electric |
Forest Dream | #228B22 | #FFD700 | #2F4F2F | Natural earth tones |
Ocean Depths | #1E90FF | #FF6347 | #191970 | Deep water vibes |
Effect Configurations
// Classic Balatro card background
<BalatroBackground
color1="#DE443B"
color2="#006BB4"
color3="#162325"
contrast={4.0}
isRotate={true}
spinSpeed={5.0}
/>
// High-energy psychedelic mode
<BalatroBackground
color1="#FF0080"
color2="#00FF00"
color3="#0000FF"
contrast={6.0}
spinSpeed={12.0}
spinAmount={0.8}
pixelFilter={400.0}
/>
// Subtle ambient background
<BalatroBackground
color1="#4A5568"
color2="#2D3748"
color3="#1A202C"
contrast={2.0}
lighting={0.2}
spinSpeed={2.0}
mouseInteraction={false}
/>
// Retro pixel art style
<BalatroBackground
color1="#FF6B35"
color2="#004E89"
color3="#1A1A1A"
pixelFilter={150.0}
contrast={5.0}
spinEase={2.0}
/>
Shader mathematics
Spiral Generation: Uses polar coordinate transformation with trigonometric functions to create authentic mathematical spirals with proper angular progression.
Iterative Feedback: Implements feedback loops with sine/cosine functions that build complexity through multiple iterations, creating the characteristic Balatro swirl patterns.
Color Blending: Calculates dynamic color mixing based on spiral intensity, using mathematical weighting to blend between the three color channels smoothly.
Mouse Distortion: Transforms mouse coordinates into spiral influence factors, affecting both rotation speed and pattern density in real-time.
Performance considerations
Shader Complexity: The fragment shader uses iterative loops and multiple trigonometric calculations. Consider reducing iterations or simplifying effects on lower-end hardware.
Pixel Filter Impact: Lower pixelFilter values create more pixelated effects but may impact performance. Values below 200 can cause frame drops on some devices.
Mouse Interaction Cost: Mouse tracking adds minimal CPU overhead but affects shader uniforms every frame. Disable for static backgrounds to optimize performance.
Color Calculation Overhead: Three-color blending with mathematical weighting is computationally intensive. Consider using fewer colors for better performance.
Common gotchas
Color Format: Only hex colors are supported. RGB values must be converted to hex format before passing to the component.
Spiral Direction: Negative spinRotation values create counter-clockwise spirals. Positive values spiral clockwise. Very high values may cause visual artifacts.
Offset Boundaries: Offset values outside -1 to 1 range may cause pattern clipping or unexpected visual behavior.
Pixel Filter Range: Extremely low pixelFilter values (below 50) may make patterns unrecognizable. Very high values (above 2000) provide minimal visual benefit.
Mouse Coordinate System: Mouse interaction uses normalized 0-1 coordinates internally. The component handles screen coordinate conversion automatically.
WebGL Context: Component manages its own WebGL context and may conflict with other WebGL applications running simultaneously.
You might also like
Plasma Background
Organic plasma effects with WebGL shaders
Northern Lights
Aurora borealis effects with color transitions
Silk Background
Flowing fabric textures with wave distortion
Light Waves
Animated light beams with noise distortion
Questions developers actually ask
React Aurora Background
Northern lights background that won't kill performance. Pure CSS aurora effect for React with TypeScript and shadcn/ui—no JavaScript loops.
React Ballpit Background
React ballpit background with Three.js physics simulation. Features realistic sphere collisions, mouse-controlled gravity, and customizable materials for interactive physics experiences.