Particle Scatter
Installation
npx shadcn@latest add https://uibrik.com/r/particle-scatter.jsonAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/particle-scatter/particle-scatter.tsx"use client"; import { cn } from "@/lib/utils"; import ShatterText from "../scatter-text/shatter-text"; import { useMemo } from "react"; import { useIsDark } from "../_shared/use-is-dark"; import { TEXT, type EffectProps } from "../_text-effects/shared"; // 19 — Each press breaks the phrase into particles, left to right, and the // particles regroup into the next phrase. It reuses the WebGL ShatterText // from /13, driven by the Change button instead of a timer and without its // looping shimmer. const SCATTER_PHRASES = ["Scatter the words", "Gather them again", "Into something new"]; // ShatterText reads its colours once when it sets up WebGL, so the palette // follows the theme class on <html> and is passed in explicitly. const SCATTER_COLORS = { light: { color: "#3f3f46", flightColor: "#71717a", glowColor: "#a1a1aa" }, dark: { color: "#e4e4e7", flightColor: "#a1a1aa", glowColor: "#fafafa" }, }; export function ParticleScatter({ play, words = SCATTER_PHRASES, waveSpeed = 1.25, particleCount = 3000, scatterMin = 18, scatterMax = 44, }: EffectProps & { words?: string[]; /** Speed of the scatter wave. */ waveSpeed?: number; /** Particles sampled across the text. */ particleCount?: number; /** Closest a particle scatters, px. */ scatterMin?: number; /** Farthest a particle scatters, px. */ scatterMax?: number; }) { const dark = useIsDark(); // one tuple identity per pair of numbers, so ShatterText doesn't rebuild every render const radius = useMemo<[number, number]>(() => [scatterMin, scatterMax], [scatterMin, scatterMax]); return ( <ShatterText phrases={words} trigger={play} shimmer={false} className={cn(TEXT, "h-[5.6em] min-h-0")} waveSpeed={waveSpeed} scatterRadius={radius} particleCount={particleCount} {...SCATTER_COLORS[dark ? "dark" : "light"]} /> ); }
Adds the files to
components/uibrik/particle-scatter. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/particle-scatter. Builds on Scatter Text.Props
ParticleScatter- words
- Type string[]
- ["Scatter the words","Gather them again","Into something new"]
- Cycled through, one per play.
- waveSpeed
- Type number
- 1.25
- Speed of the scatter wave.
- particleCount
- Type number
- 3000
- Particles sampled across the text.
- scatterMin
- Type number
- 18
- Closest a particle scatters.
- scatterMax
- Type number
- 44
- Farthest a particle scatters.
- playrequired
- Type number
- –
- Each change plays the effect again; 0 shows its resting state.