cursor-driven-particle-typography
componentry/cursor-driven-particle-typographyFreeComponent
Component for cursor-driven-particle-typography
Live preview
live · rendered by the registry
Rendered by componentry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://componentry.dev/r/cursor-driven-particle-typography.jsonSource
1"use client";23import { cn } from "@workspace/ui/lib/utils";4import React, { useEffect, useRef } from "react";56export interface CursorDrivenParticleTypographyProps {7 /** Additional CSS classes */8 className?: string;9 /** The text to render */10 text: string;11 /** Font size in pixels */12 fontSize?: number;13 /** Font family */14 fontFamily?: string;15 /** Size of each particle */16 particleSize?: number;17 /** Density of particles (lower number = more particles, minimum 1) */18 particleDensity?: number;19 /** How strongly the cursor pushes particles away */20 dispersionStrength?: number;21 /** Speed at which particles return to origin */22 returnSpeed?: number;23 /** Custom color for particles. Overrides inherited text color if set. */24 color?: string;25}2627class Particle {28 x: number;29 y: number;30 originX: number;31 originY: number;32 vx: number;33 vy: number;34 size: number;35 color: string;36 dispersion: number;37 returnSpd: number;3839 constructor(40 x: number,41 y: number,42 size: number,43 color: string,44 dispersion: number,45 returnSpd: number46 ) {47 this.x = x + (Math.random() - 0.5) * 10; // start with slight randomness48 this.y = y + (Math.random() - 0.5) * 10;49 this.originX = x;50 this.originY = y;51 this.vx = (Math.random() - 0.5) * 5;52 this.vy = (Math.random() - 0.5) * 5;53 this.size = size;54 this.color = color;55 this.dispersion = dispersion;56 this.returnSpd = returnSpd;57 }5859 update(mouseX: number, mouseY: number) {60 const dx = mouseX - this.x;61 const dy = mouseY - this.y;62 const distance = Math.sqrt(dx * dx + dy * dy);6364 // Physics interaction with mouse65 const interactionRadius = 120; // 120px interaction radius6667 if (distance < interactionRadius && mouseX !== -1000 && mouseY !== -1000) {68 const forceDirectionX = dx / distance;69 const forceDirectionY = dy / distance;7071 const force = (interactionRadius - distance) / interactionRadius;7273 // Calculate repulsion74 const repulsionX = forceDirectionX * force * this.dispersion;75 const repulsionY = forceDirectionY * force * this.dispersion;7677 this.vx -= repulsionX;78 this.vy -= repulsionY;79 }8081 // Return to origin (spring physics)82// … truncated
More from componentry
All 59 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradientanimated-gradient | componentry | Components | Free | no deps | |
| ASCII Effectascii-effect | componentry | Components | Free | no deps | |
| Aurora Flowaurora-flow | componentry | Components | Free | no deps | |
| auth-modalauth-modal | componentry | Components | Free | no deps | |
| border-beamborder-beam | componentry | Components | Free | no deps | |
| circuit-boardcircuit-board | componentry | Components | Free | no deps | |
| closing-plasmaclosing-plasma | componentry | Components | Free | no deps | |
| collection-surfercollection-surfer | componentry | Components | Free | no deps |
