Join our Discord Community

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.

Powered by

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:

Loading component...

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

PropTypeDefaultDescription
spinRotationnumber-2.0Base rotation speed multiplier (-10 to 10)
spinSpeednumber7.0Animation speed for time-based effects (0.1 to 20)
offset[number, number][0.0, 0.0]Pattern offset coordinates (-1 to 1 each)
color1string"#DE443B"Primary spiral color (hex format)
color2string"#006BB4"Secondary spiral color (hex format)
color3string"#162325"Accent/background color (hex format)
contrastnumber3.5Pattern contrast intensity (1 to 10)
lightingnumber0.4Lighting effect strength (0 to 2)
spinAmountnumber0.25Spiral distortion amount (0 to 1)
pixelFilternumber745.0Pixel resolution filter (100 to 2000)
spinEasenumber1.0Spiral easing curve factor (0.1 to 5)
isRotatebooleanfalseEnable continuous rotation animation
mouseInteractionbooleantrueEnable mouse-based distortion effects
classNamestring-Additional CSS classes
...propsHTMLAttributes<HTMLDivElement>-All standard div props

Color Combinations

Classic Balatro-inspired color schemes:

ThemeColor1Color2Color3Visual Style
Classic Red#DE443B#006BB4#162325Traditional Balatro aesthetic
Neon Nights#FF0080#00FFFF#000000High-contrast electric
Forest Dream#228B22#FFD700#2F4F2FNatural earth tones
Ocean Depths#1E90FF#FF6347#191970Deep 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

Questions developers actually ask