# Wave Physics Loader

> Wave Physics Loader loading animation.

- Kind: Element
- Page: https://ownlyplans.com/bhaskar/wave-physics-loader/
- Licence: MIT (do anything, keep the notice)
- Original source: amicro by Syed Subhan Uddin (https://github.com/Subhan-code/Amicro--Micro-transitions-/blob/main/registry/ui/loading/wave-physics-loader.tsx), MIT licence

## Install

```bash
npx shadcn@latest add https://ownlyplans.com/r/bhaskar/wave-physics-loader.json
```

## Code

Built with React + Motion + Tailwind CSS.

Dependencies: framer-motion

`wave-physics-loader.tsx`

```tsx
/*
 * MIT License
 *
 * Copyright (c) 2026 Syed Subhan Uddin
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
// Wave Physics Loader from amicro by Syed Subhan Uddin
// https://github.com/Subhan-code/Amicro--Micro-transitions-/blob/main/registry/ui/loading/wave-physics-loader.tsx
// MIT License, Copyright (c) 2026 Syed Subhan Uddin. Full licence: https://github.com/Subhan-code/Amicro--Micro-transitions-/blob/main/LICENSE
// Styled with Tailwind CSS. Needs: framer-motion

import { motion } from 'framer-motion';
import { useMemo } from 'react';

export function WavePhysicsLoader({ theme = 'light' }: { theme?: 'light' | 'dark' }) {
  const numBars = 15;
  const barWidth = 12; 
  const barGap = 8; 
  const barTotalWidth = barWidth + barGap;
  
  const numFrames = 201;
  const B = 4; 
  const maxBounce = 60; 
  const baseBarH = 16;
  const wavePeakH = 48; 

  const { bars, ballX, ballY, ballScaleX, ballScaleY, times } = useMemo(() => {
    const barsData = Array.from({ length: numBars }).map(() => ({ 
      heights: [] as string[],
      colors: [] as string[],
    }));
    const bX: string[] = [];
    const bY: string[] = [];
    const bScaleX: number[] = [];
    const bScaleY: number[] = [];
    const tArr: number[] = [];
    
    for (let k = 0; k < numFrames; k++) {
      const t = k / (numFrames - 1);
      tArr.push(t);
      
      const x_frac = t < 0.5 ? t / 0.5 : (1 - t) / 0.5;
      const ball_idx = x_frac * (numBars - 1);
      
      bX.push(`${ball_idx * barTotalWidth}px`);
      
      let bounce_f = (x_frac * B) % 1.0;
      if (x_frac === 1 || x_frac === 0) bounce_f = 0;
      
      const bounce_h = 4 * bounce_f * (1 - bounce_f);
      const height_factor = Math.max(0, 1 - bounce_h * 2);
      
      const ball_indent = height_factor * 20; 
      const ball_y = (baseBarH + wavePeakH - ball_indent) + bounce_h * maxBounce;
      bY.push(`-${ball_y}px`);
      
      const squish = height_factor; 
      bScaleY.push(1 - squish * 0.3);
      bScaleX.push(1 + squish * 0.25);
      
      for (let i = 0; i < numBars; i++) {
        const dist = Math.abs(i - ball_idx);
        
        let wave_val = 0;
        if (dist < 3) {
          wave_val = Math.cos((dist / 3) * (Math.PI / 2));
        }
        
        let indent = 0;
        if (dist < 1.5) {
          const indent_dist = Math.cos((dist / 1.5) * (Math.PI / 2));
          indent = indent_dist * height_factor * 20;
        }
        
        const bar_h = baseBarH + wave_val * wavePeakH - indent;
        barsData[i].heights.push(`${Math.max(4, bar_h)}px`); 
        
        // Colors for Light Theme: zinc-200 to zinc-800
        const isDark = theme === 'dark';
        let r, g, b;
        if (isDark) {
          r = Math.round(39 + wave_val * (228 - 39));
          g = Math.round(39 + wave_val * (228 - 39));
          b = Math.round(42 + wave_val * (231 - 42));
        } else {
          r = Math.round(228 - wave_val * (228 - 39));
          g = Math.round(228 - wave_val * (228 - 39));
          b = Math.round(231 - wave_val * (231 - 42));
        }
        barsData[i].colors.push(`rgb(${r}, ${g}, ${b})`);
      }
    }
    
    return { bars: barsData, ballX: bX, ballY: bY, ballScaleX: bScaleX, ballScaleY: bScaleY, times: tArr };
  }, [theme]);

  return (
    <div className="relative flex flex-col items-center justify-center w-full scale-[0.6] sm:scale-75 md:scale-100">
      <div className="relative flex items-end justify-start h-48 space-x-2 w-[292px]">
        {bars.map((bar, i) => (
          <motion.div
            key={i}
            className="w-3 rounded-full origin-bottom"
            style={{ height: '16px', backgroundColor: theme === 'dark' ? 'rgb(39, 39, 42)' : 'rgb(228, 228, 231)' }}
            animate={{
              height: bar.heights,
              backgroundColor: bar.colors,
            }}
            transition={{
              duration: 4,
              repeat: Infinity,
              times: times,
              ease: 'linear',
            }}
          />
        ))}
        
        <motion.div
          className="absolute w-3 h-3 bg-zinc-900 dark:bg-white rounded-full z-10 shadow-sm"
          style={{ bottom: 0, left: 0, transformOrigin: 'bottom center' }}
          animate={{
            x: ballX,
            y: ballY,
            scaleX: ballScaleX,
            scaleY: ballScaleY,
          }}
          transition={{
            duration: 4,
            repeat: Infinity,
            times: times,
            ease: 'linear',
          }}
        />
      </div>
    </div>
  );
}
```

## Licence notice

Keep this notice with the code (the licence requires it).

```text
MIT License

Copyright (c) 2026 Syed Subhan Uddin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

## About

Wave Physics Loader loading animation.

A React loader built with Motion and Tailwind CSS. Open the Preview tab to try it, then copy the code from the Code tab or install it with the shadcn command. Hand this page's link to Claude or any AI tool and it can read the code straight from the page.

Credit: from the amicro library by Syed Subhan Uddin (https://github.com/Subhan-code/Amicro--Micro-transitions-), shared here under the MIT licence.

MIT License

Copyright (c) 2026 Syed Subhan Uddin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---
Also available as JSON: https://ownlyplans.com/bhaskar/wave-physics-loader/?format=json
MCP server: https://ownlyplans.com/mcp
