Math Curves
boldkit/math-curvesFreeUtility
Framework-agnostic math engine for parametric curve animations (rose, lissajous, butterfly, hypotrochoid, cardioid, lemniscate, fourier, spiral, heart)
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/math-curves.jsonSource
1/**2 * math-curves.ts3 * Framework-agnostic math engine for parametric curve animations.4 * All coordinates are in [0, 100] SVG space, center at (50, 50).5 * progress: 0–1 (fraction of full curve loop)6 * detailScale: 0.52–1.0 (breathing oscillator, see getDetailScale)7 */89export type LoaderCurveKey =10 | 'rose' | 'lissajous' | 'butterfly' | 'hypotrochoid'11 | 'cardioid' | 'lemniscate' | 'fourier' | 'rose3'12 | 'astroid' | 'deltoid' | 'nephroid' | 'epicycloid'13 | 'superellipse' | 'triskelion' | 'involute'14 | 'spiral' | 'heart'1516export type ProgressCurveKey =17 | 'spiral' | 'heart' | 'lissajous' | 'cardioid' | 'rose'18 | 'astroid' | 'superellipse' | 'deltoid' | 'nephroid'1920export type BackgroundCurveKey =21 | 'rose' | 'lissajous' | 'fourier' | 'spiral'22 | 'triskelion' | 'involute' | 'epicycloid'2324export type CurveKey = LoaderCurveKey | ProgressCurveKey | BackgroundCurveKey2526type Point = { x: number; y: number }2728interface CurveDefinition {29 /** t parameter range — progress 0→1 maps to tMin→tMax */30 tMin: number31 tMax: number32 /** Default breathing cycle duration in ms */33 pulseDurationMs: number34 /** Default segment count for buildPath */35 defaultSegments: number36 /** Core parametric function — returns {x, y} in [0,100] space */37 compute: (t: number, detailScale: number) => Point38 /**39 * Progress fractions (0–1 exclusive) where the curve is discontinuous.40 * buildPath will insert M (moveto) instead of L at these points.41 */42 discontinuities?: number[]43}4445const CURVE_DEFS: Record<string, CurveDefinition> = {46 // 5-petal rose: r = a·cos(5θ), odd k → full flower in [0, π]47 rose: {48 tMin: 0,49 tMax: Math.PI,50 pulseDurationMs: 5000,51 defaultSegments: 300,52 compute: (t, ds) => {53 const a = 30 + ds * 854 const r = a * Math.cos(5 * t)55 return { x: 50 + r * Math.cos(t), y: 50 + r * Math.sin(t) }56 },57 },5859 // 3-petal rose: r = a·cos(3θ), odd k → full flower in [0, π]60 rose3: {61 tMin: 0,62 tMax: Math.PI,63 pulseDurationMs: 5500,64 defaultSegments: 240,65 compute: (t, ds) => {66 const a = 34 + ds * 667 const r = a * Math.cos(3 * t)68 return { x: 50 + r * Math.cos(t), y: 50 + r * Math.sin(t) }69 },70 },7172 // Lissajous figure (3:4 ratio): x = A·sin(3t + π/2), y = B·sin(4t)73 lissajous: {74 tMin: 0,75 tMax: 2 * Math.PI,76 pulseDurationMs: 4800,77 defaultSegments: 240,78 compute: (t, ds) => {79 const A = 34 + ds * 680 const B = A * 0.8681// … truncated
What it pulls in
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Chart Exportchart-export | boldkit | Utilities | Free | no deps | |
| Motion Coremotion-core | boldkit | Utilities | Free | no deps | |
| Utilsutils | boldkit | Utilities | Free | 2 deps |
