Vortex
threecn/vortexFreeComponent
A spiral galaxy of points fading from --primary at the core to --muted-foreground at the rim.
Install it
npx shadcn@latest add https://threecn.dev/r/vortex.jsonSource
1"use client"23import * as React from "react"4import { useFrame } from "@react-three/fiber"5import * as THREE from "three"67import {8 SceneContainer,9 type SceneContainerProps,10} from "@/components/threecn/scene-container"11import {12 useShadcnTheme,13 type ThemeMode,14} from "@/components/hooks/use-shadcn-theme"1516function seedVortex(count: number, arms: number) {17 const positions = new Float32Array(count * 3)18 const radii = new Float32Array(count)19 const radius = 620 for (let i = 0; i < count; i++) {21 const r = Math.pow(Math.random(), 0.6) * radius22 const arm = i % arms23 const branch = (arm / arms) * Math.PI * 224 const spin = r * 0.525 const scatter = (Math.random() - 0.5) * (0.6 + r * 0.08)26 const angle = branch + spin27 positions[i * 3] = Math.cos(angle) * r + scatter28 positions[i * 3 + 1] = (Math.random() - 0.5) * 0.629 positions[i * 3 + 2] = Math.sin(angle) * r + scatter30 radii[i] = r / radius31 }32 return { positions, radii }33}3435function Spiral({36 count,37 speed,38 arms,39 theme,40}: {41 count: number42 speed: number43 arms: number44 theme: ThemeMode45}) {46 const pointsRef = React.useRef<THREE.Points>(null)47 const { primaryColor, mutedColor } = useShadcnTheme(theme)4849 const { positions, radii } = React.useMemo(50 () => seedVortex(count, arms),51 [count, arms]52 )5354 const colors = React.useMemo(() => {55 const arr = new Float32Array(count * 3)56 const c = new THREE.Color()57 for (let i = 0; i < count; i++) {58 c.copy(primaryColor).lerp(mutedColor, radii[i])59 arr[i * 3] = c.r60 arr[i * 3 + 1] = c.g61 arr[i * 3 + 2] = c.b62 }63 return arr64 }, [count, radii, primaryColor, mutedColor])6566 useFrame((_, delta) => {67 if (pointsRef.current) pointsRef.current.rotation.y += delta * 0.12 * speed68 })6970 return (71 <points ref={pointsRef} rotation={[0.5, 0, 0]}>72 <bufferGeometry>73 <bufferAttribute attach="attributes-position" args={[positions, 3]} />74 <bufferAttribute attach="attributes-color" args={[colors, 3]} />75 </bufferGeometry>76 <pointsMaterial77 vertexColors78 size={0.05}79 sizeAttenuation80 transparent81 opacity={0.9}82 depthWrite={false}83 blending={THREE.AdditiveBlending}84 />85 </points>86 )87}8889export type VortexProps = {90 /** Number of points. */91 count?: number92 /** Rotation speed multiplier. */93 speed?: number94 /** Number of spiral arms. */95 arms?: number96 className?: string97 theme?: ThemeMode98// … truncated
What it pulls in
npm packages
Files it writes
More from threecn
All 28 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AuroraRibbonsaurora-ribbons | threecn | Components | Free | 3 deps · 3 files | |
| Boidsboids | threecn | Components | Free | 3 deps · 3 files | |
| Clothcloth | threecn | Components | Free | 3 deps · 3 files | |
| Crystalcrystal | threecn | Components | Free | 3 deps · 3 files | |
| CubeWavecube-wave | threecn | Components | Free | 3 deps · 3 files | |
| CurlFlowcurl-flow | threecn | Components | Free | 3 deps · 3 files | |
| DnaHelixdna-helix | threecn | Components | Free | 3 deps · 3 files | |
| FloatingCard3Dfloating-card-3d | threecn | Components | Free | 3 deps · 3 files |
