StrangeAttractor
threecn/strange-attractorFreeComponent
The Aizawa attractor integrated live into one glowing orbit that never repeats, colored --primary to --accent with a sweeping head.
Install it
npx shadcn@latest add https://threecn.dev/r/strange-attractor.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"1516// Aizawa attractor coefficients — a classic set that traces a spindle wrapped17// in orbiting loops.18const A = 0.9519const B = 0.720const C = 0.621const D = 3.522const E = 0.2523const F = 0.12425/** Integrate the attractor into a centered, ~4-unit point path (run once). */26function traceAttractor(points: number) {27 const path = new Float32Array(points * 3)28 let x = 0.129 let y = 030 let z = 031 const dt = 0.00632 let minX = Infinity33 let maxX = -Infinity34 let minY = Infinity35 let maxY = -Infinity36 let minZ = Infinity37 let maxZ = -Infinity3839 for (let i = 0; i < points; i++) {40 const dx = (z - B) * x - D * y41 const dy = D * x + (z - B) * y42 const dz =43 C + A * z - (z * z * z) / 3 - (x * x + y * y) * (1 + E * z) + F * z * x * x * x44 x += dx * dt45 y += dy * dt46 z += dz * dt47 path[i * 3] = x48 path[i * 3 + 1] = y49 path[i * 3 + 2] = z50 if (x < minX) minX = x51 if (x > maxX) maxX = x52 if (y < minY) minY = y53 if (y > maxY) maxY = y54 if (z < minZ) minZ = z55 if (z > maxZ) maxZ = z56 }5758 const cx = (minX + maxX) / 259 const cy = (minY + maxY) / 260 const cz = (minZ + maxZ) / 261 const span = Math.max(maxX - minX, maxY - minY, maxZ - minZ) || 162 const scale = 4 / span63 for (let i = 0; i < points; i++) {64 path[i * 3] = (path[i * 3] - cx) * scale65 path[i * 3 + 1] = (path[i * 3 + 1] - cy) * scale66 path[i * 3 + 2] = (path[i * 3 + 2] - cz) * scale67 }68 return path69}7071/** Expand the point path into consecutive line segments for <lineSegments>. */72function toSegments(path: Float32Array) {73 const n = path.length / 374 const seg = new Float32Array((n - 1) * 2 * 3)75 let o = 076 for (let i = 0; i < n - 1; i++) {77 seg[o++] = path[i * 3]78 seg[o++] = path[i * 3 + 1]79 seg[o++] = path[i * 3 + 2]80 seg[o++] = path[(i + 1) * 3]81 seg[o++] = path[(i + 1) * 3 + 1]82 seg[o++] = path[(i + 1) * 3 + 2]83 }84 return seg85}8687function Attractor({88 points,89 speed,90 theme,91}: {92 points: number93 speed: number94 theme: ThemeMode95}) {96 const { primaryColor, accentColor, isDark } = useShadcnTheme(theme)97 const geoRef = React.useRef<THREE.BufferGeometry>(null)98// … 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 |
