Strands
A bundle of fine lines twisting like fibre in a current. Use case: Audio or data product.
Backgrounds · React · Tailwind CSS v4 · MIT · TypeScript
Install
npx shadcn@latest add https://www.kavynui.com/r/shader-strands.json
Or register the library once (npx shadcn@latest registry add @kavynui=https://www.kavynui.com/r/{name}.json) and run npx shadcn@latest add @kavynui/shader-strands. Registry item: /r/shader-strands.json.
Use
import ShaderStrands from '@/components/kavyn/shader-strands'
export default function Page() {
return <ShaderStrands />
}
Files: components/kavyn/shader-strands.tsx, components/kavyn/shader-bg.tsx. Packages: react.
Source: shader-strands.tsx
'use client'
import ShaderBackground, { type ShaderBackgroundProps } from './shader-bg'
const FRAG = `
uniform float uCount;
void main(){
vec2 p=centered();float x=p.x*uScale;float t=uTime*.35;vec2 m=pointer();
float v=0.,k=0.;
for(int i=0;i<48;i++){
float f=float(i);if(f>=uCount)break;
float u=f/uCount;
float env=.5+.5*sin(x*1.1+u*4.+t*.4);
float y=(u-.5)*.55*env+.3*sin(x*2.1+u*6.283+t)*(noise(vec2(x*.6+f*.37,t*.25))-.2)+.04*sin(x*5.3-t*1.3+f);
y+=uMouse.w*(m.y-y)*.6*exp(-7.*abs(p.x-m.x));
float d=abs(p.y-y)*uRes.y/uPx;
float line=smoothstep(1.3,0.,d)*.5+.5/(d+5.);
v+=line*(.3+.7*u);k+=line*u;
}
paint(v*.6,k/(v+.001));
}
`
export interface ShaderStrandsProps extends ShaderBackgroundProps {
/** Number of lines, up to 48. */
count?: number
}
// A bundle of fine lines that twists like fibre in a current and leans toward the pointer.
// Ink and paper come from your theme (--tx on --bg), so it works in light and dark. Pass `color` to tint it.
export default function ShaderStrands({ count = 22, color = '', color2 = '', speed = 1, intensity = 1, scale = 1, interactive = true, allowSoftware = true, className = '', style, children }: ShaderStrandsProps) {
return (
<ShaderBackground frag={FRAG} uniforms={{ uCount: count }} color={color} color2={color2} speed={speed} intensity={intensity} scale={scale} interactive={interactive} allowSoftware={allowSoftware} className={className} style={style}>
{children}
</ShaderBackground>
)
}
More in Backgrounds
- Silk - Satin folds that drift and catch the light. For: Luxury landing.
- Liquid Chrome - Slow liquid-metal reflections that part around the pointer. For: AI product hero.
- Horizon - The lit edge of a planet rising under your headline. For: Waitlist page.
- Light Rays - Shafts of light falling from above, with dust in the beams. For: Pricing page header.
- Polar Veil - Aurora curtains with fine rays over a starfield. For: Sign-up screen.
- Ink Current - Ink folding through water, bending away from the pointer. For: Launch page.
- Pool Light - Light dancing on a pool floor, gathering under the pointer. For: Travel landing.
- Wave Lattice - A dot grid carrying waves, rippling out from the pointer. For: Dev tool hero.