Hero Vec S2
A large illustrative hero SVG for the lesson "a matrix is a function on space". A 7×7 dot grid connected by thin lines warps between three 2×2 matrix transforms with spring physics — identity, then a shear, then a rotation + scale. Inner dots animate first; outer dots last. Each dot's glow halo brightens proportionally to its displacement. A tiny matrix readout in the bottom-right corner tracks the active transform. Theme-driven via currentColor + a single accentColor prop; reduced-motion users see a static frame.
Customize
Hero illustration
400px
accent
false
Installation
npx shadcn@latest add https://craftbits.dev/r/hero-vec-s2.jsonUsage
import { HeroVecS2 } from "@craft-bits/core/svg/hero-vec-s2";
<HeroVecS2 size={400} />
// Tint via the parent text color.
<div className="text-cb-accent">
<HeroVecS2 />
</div>Understanding the component
- Three-phase warp loop. A single
useEffectcycles through the matrices[1, 0, 0, 1](identity),[1.0, 0.6, -0.3, 1.0](shear), and[0.8, -0.5, 0.5, 0.8](rotation + scale). After a 1.2-second entrance the first warp begins, then each phase holds for ~3 seconds before the next. The loop runs continuously while mounted; every timer is cleaned up on unmount and when reduced-motion changes. - Ripple stagger. Every dot's transition is delayed by its Manhattan distance from the origin (30 ms per ring), so inner dots move first and outer dots last — the warp reads as a wave radiating outward.
- Displacement-driven glow. Each dot's glow halo opacity is proportional to how far that dot moved between the previous and current matrix, capped at 0.55. The halo fades back to zero ~900 ms after the dot starts moving, so the brightest dots correspond to the largest local distortion.
- Motion values, not re-renders. Each of the 49 dots owns a
useMotionValue+useSpringtriple (x, y, glow), so the React tree never re-renders during the loop. The matrix-label readout updates imperatively via a ref. Dot positions useSPRINGS.smooth; the glow halos use a tighter inline spring so they settle within one cycle. - Theme-driven color. The surface, caption, and matrix label use
currentColor, so the host tints the chrome with anytext-cb-*utility. TheaccentColorprop tints the dots, connecting lines, and glow halos; theoriginColorprop sets the centre / origin dot (defaults tovar(--cb-bg)so the origin reads as a pin against the warped grid). - Reduced-motion safe. When
prefers-reduced-motion: reduceis set, or thepausedprop istrue, the loop short-circuits to a single static frame with the shear matrix already applied — no timers, no spring updates.
Variants / Examples
// Paused — useful for thumbnails / OG images.
<HeroVecS2 paused />
// Compact thumbnail.
<HeroVecS2 size={240} />
// Explicit accent color.
<HeroVecS2 size={480} accentColor="var(--cb-accent)" />
// Custom hex.
<HeroVecS2 accentColor="#8b5cf6" />
// Custom origin pin colour (e.g. on a non-bg surface).
<HeroVecS2 originColor="#ffffff" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | 400 | Pixel width. Height is computed from the 400×280 aspect ratio. |
accentColor | string | 'currentColor' | Any CSS color. Tints the grid dots, connecting lines, glow halos, and matrix readout. |
originColor | string | 'var(--cb-bg, #0b0b0d)' | Color of the centre / origin dot — usually the host's background so it reads as a pin. |
paused | boolean | false | When true, render a single static frame instead of looping. |
className | string | — | Extra classes merged onto the root SVG. |
...rest | SVGAttributes<SVGSVGElement> | — | Other SVG props forwarded to the root. |
Accessibility
- The root SVG carries
aria-hidden="true"— the illustration is decorative; pair it with a visible heading or caption in its surrounding context. - Motion respects
prefers-reduced-motion: reduce: the loop short-circuits and renders a static frame. - All colors flow from
currentColor+ theaccentColor/originColorprops, so contrast tracks the consumer's text and accent tokens — no hardcoded hex values.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/chrome/icons/heroes/HeroVecS2.tsx). - Inspiration: classic linear-algebra visualisations — "a matrix is a function on space".