Antigravity
react-bits/Antigravity-TS-TWFreeComponent
3D antigravity particle field that repels from the cursor with smooth motion.
Live preview
live · rendered by the registry
Rendered by @react-bits on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.reactbits.dev/r/Antigravity-TS-TW.jsonSource
1import { Canvas, useFrame, useThree } from '@react-three/fiber';2import React, { useMemo, useRef } from 'react';3import * as THREE from 'three';45interface AntigravityProps {6 count?: number;7 magnetRadius?: number;8 ringRadius?: number;9 waveSpeed?: number;10 waveAmplitude?: number;11 particleSize?: number;12 lerpSpeed?: number;13 color?: string;14 autoAnimate?: boolean;15 particleVariance?: number;16 rotationSpeed?: number;17 depthFactor?: number;18 pulseSpeed?: number;19 particleShape?: 'capsule' | 'sphere' | 'box' | 'tetrahedron';20 fieldStrength?: number;21}2223const AntigravityInner: React.FC<AntigravityProps> = ({24 count = 300,25 magnetRadius = 10,26 ringRadius = 10,27 waveSpeed = 0.4,28 waveAmplitude = 1,29 particleSize = 2,30 lerpSpeed = 0.1,31 color = '#FF9FFC',32 autoAnimate = false,33 particleVariance = 1,34 rotationSpeed = 0,35 depthFactor = 1,36 pulseSpeed = 3,37 particleShape = 'capsule',38 fieldStrength = 1039}) => {40 const meshRef = useRef<THREE.InstancedMesh>(null);41 const { viewport } = useThree();42 const dummy = useMemo(() => new THREE.Object3D(), []);4344 const lastMousePos = useRef({ x: 0, y: 0 });45 const lastMouseMoveTime = useRef(0);46 const virtualMouse = useRef({ x: 0, y: 0 });4748 const particles = useMemo(() => {49 const temp = [];50 const width = viewport.width || 100;51 const height = viewport.height || 100;5253 for (let i = 0; i < count; i++) {54 const t = Math.random() * 100;55 const factor = 20 + Math.random() * 100;56 const speed = 0.01 + Math.random() / 200;57 const xFactor = -50 + Math.random() * 100;58 const yFactor = -50 + Math.random() * 100;59 const zFactor = -50 + Math.random() * 100;6061 const x = (Math.random() - 0.5) * width;62 const y = (Math.random() - 0.5) * height;63 const z = (Math.random() - 0.5) * 20;6465 const randomRadiusOffset = (Math.random() - 0.5) * 2;6667 temp.push({68 t,69 factor,70 speed,71 xFactor,72 yFactor,73 zFactor,74 mx: x,75 my: y,76 mz: z,77 cx: x,78 cy: y,79 cz: z,80 vx: 0,81 vy: 0,82 vz: 0,83 randomRadiusOffset84 });85 }86 return temp;87 }, [count, viewport.width, viewport.height]);8889 useFrame(state => {90 const mesh = meshRef.current;91 if (!mesh) return;9293 const { viewport: v, pointer: m } = state;9495 const mouseDist = Math.sqrt(Math.pow(m.x - lastMousePos.current.x, 2) + Math.pow(m.y - lastMousePos.current.y, 2));9697// … truncated
What it pulls in
npm packages
Files it writes
More from @react-bits
All 556 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AnimatedContentAnimatedContent-JS-CSS | @react-bits | Components | Free | 1 dep | |
| AnimatedContentAnimatedContent-JS-TW | @react-bits | Components | Free | 1 dep | |
| AnimatedContentAnimatedContent-TS-CSS | @react-bits | Components | Free | 1 dep | |
| AnimatedContentAnimatedContent-TS-TW | @react-bits | Components | Free | 1 dep | |
| AnimatedListAnimatedList-JS-CSS | @react-bits | Components | Free | 1 dep · 2 files | |
| AnimatedListAnimatedList-JS-TW | @react-bits | Components | Free | 1 dep | |
| AnimatedListAnimatedList-TS-CSS | @react-bits | Components | Free | 1 dep · 2 files | |
| AnimatedListAnimatedList-TS-TW | @react-bits | Components | Free | 1 dep |
