When interface designers dream of the ultimate animation, they envision continuous fluid transformation: a single elemental container that never cuts, jumps, or flashes. It morphs from a humble button into an indeterminate loader, checks off into a confirmation state, unfurls into a dynamic island, expands into a full music controller, stretches into a volume slider, flips into a toggle, slides into liquid segmented tabs, opens into a self-drawing analytics chart with hover tooltips, collapses into a command palette, fires a toast notification, and finally returns seamlessly to the initial button.
And it does all of this locked to a 120 BPM musical beat grid, driven by an active cursor performing real clicks, drags, and hover gestures.
Below is the live, zero-dependency engine rendered in real time.
In this article, we dissect how this artifact was conceived, the prompt engineering framework that guided the AI to generate it, the mathematical physics powering its motion, and how to integrate such deterministic systems into production web applications.
Most attempts to generate complex UI animations with LLMs yield generic CSS keyframe transitions: bouncy curves, arbitrary timing functions (cubic-bezier(0.68, -0.55, 0.27, 1.55)), inconsistent icon stroke weights, and chaotic state machines.
The prompt that birthed this engine succeeded because it imposed strict physical and mathematical constraints:
<direction>
Dribbble-level UI motion. One shape, never cut: every state is the same element
morphing its size, radius and color while its content swaps with a short blur.
A cursor drives every change with real clicks and drags. Light warm-gray canvas,
black and white components, one clean UI font (Geist). Springs everywhere, a tiny
overshoot at most. The camera zooms so each state fills the frame. The last frame
is the first frame, so it loops.
Banned: bouncy easing, particle bursts, glows, gradients on UI chrome,
mismatched icon strokes, dead time, anything that looks like a template.
</direction>
Notice the explicit Banned section. Eliminating "bouncy easing" immediately forces the generator away from amateurish CSS bezier hacks. Eliminating "gradients, particle bursts, and glows" anchors the visual aesthetic into high-end, brutalist minimalism reminiscent of Dieter Rams and modern Swiss software design.
Instead of describing animations in loose seconds, the prompt bound the choreography to musical structure:
<structure>
120 BPM, 7 bars, something happens on every beat.
Button → loader → check → dynamic island → music player with a play/pause morph
→ scrub the progress bar → volume slider that stretches when dragged past max
→ toggle flips on the beat → liquid tab indicator → chart that draws itself
→ collapses into ⌘K → type to filter → enter → toast → back to button.
</structure>
At , each beat is precisely (). Seven bars of time equal , establishing an exact cycle period of:
Every state transition, click, drag, and morph aligns with an integer beat or an exact musical sub-division (eighth notes at , sixteenth notes at ).
The single most critical architectural breakthrough of this engine is the elimination of state accumulation.
In traditional frontend animation libraries (such as Framer Motion or React Spring), components rely on continuous numerical integration (x += v * dt). If a frame drops from to , the integrator accumulates numerical error. Scrubbing backwards requires running the simulation in reverse or caching state arrays.
In this engine, there are no CSS transitions, no setInterval, and zero mutable state carried between frames. All layout properties—width, height, border radius, camera zoom, cursor position, and layer opacities—are derived through a pure mathematical function:
function seek(rawT) {
const t = ((rawT % 14.0) + 14.0) % 14.0;
// 1. Container dimensions via closed-form analytical springs
const w = multiStepSpring(t, widthSteps, 22, 0.86);
const h = multiStepSpring(t, heightSteps, 22, 0.86);
const r = multiStepSpring(t, radiusSteps, 20, 0.88);
const zoom = multiStepSpring(t, cameraZoomSteps, 16, 0.90);
morphContainer.style.width = `${w}px`;
morphContainer.style.height = `${h}px`;
morphContainer.style.borderRadius = `${r}px`;
cameraEl.style.transform = `scale(${zoom})`;
// 2. Continuous layer opacity & blur cross-fades
// 3. Precision icon and progress interpolation
// 4. Cubic Hermite cursor trajectory
}
Because seek(t) is idempotent, you can jump to instantaneously. You can scrub backwards at , render in parallel across multiple worker threads, or pause at any millisecond without visual drift.
How do you compute a spring's position at arbitrary time without simulating every intervening step?
You solve the second-order linear ordinary differential equation (ODE) of a damped harmonic oscillator:
Normalizing by mass , we define natural angular frequency and damping ratio . For underdamped systems (), the closed-form unit step response from rest at to target is:
where represents the damped angular frequency.
Here is the exact JavaScript implementation used in the engine:
function springUnitStep(t, omega, zeta) {
if (t <= 0) return 0;
const wd = omega * Math.sqrt(Math.max(0.001, 1 - zeta * zeta));
const decay = Math.exp(-zeta * omega * t);
return 1 - decay * (Math.cos(wd * t) + (zeta * omega / wd) * Math.sin(wd * t));
}
Because the underlying differential equation is Linear Time-Invariant (LTI), the response to a sequence of target changes is the linear superposition of their individual step responses!
If a container's width changes from to at , and then to at , the position at any time is simply:
function multiStepSpring(t, steps, omega = 24, zeta = 0.88) {
let val = steps[0][1];
for (let i = 1; i < steps.length; i++) {
const tStep = steps[i][0];
const delta = steps[i][1] - steps[i - 1][1];
if (t > tStep) {
val += delta * springUnitStep(t - tStep, omega, zeta);
}
}
return val;
}
This remarkable formulation provides pure time-seekability with true organic spring kinetics, zero numerical drift, and microsecond evaluation times.
When standard UI elements move (such as macOS segmented controls or iOS toggle knobs), they typically translate as rigid bodies.
To create the organic, liquid "stretch-and-snap" effect seen on Dribbble, the engine decouples the leading edge and the trailing edge of the element onto two completely different spring configurations:
// Liquid Tab Indicator Transition
if (t >= 6.0 && t < 7.0) {
// Trailing edge: stiffer spring (omega = 24, zeta = 0.85)
const leftVal = multiStepSpring(t, tabLeftSteps, 24, 0.85);
// Leading edge: faster spring triggered slightly earlier (omega = 30, zeta = 0.80)
const rightVal = multiStepSpring(t, tabRightSteps, 30, 0.80);
tabIndicator.style.left = `${leftVal}px`;
tabIndicator.style.width = `${Math.max(105, rightVal - leftVal)}px`;
}
- At the onset of motion (), the right edge rushes forward under higher frequency ().
- The left edge lags behind at .
- The distance expands, visually stretching the indicator into an elongated droplet.
- As the right edge decelerates near its target, the left edge catches up rapidly, restoring the original pill geometry.
The exact same technique powers the toggle knob at , creating an organic, fluid flick rather than a mechanical slide.
Animations often feel sterile when elements move spontaneously without apparent cause. In this engine, a virtual cursor acts as the causal driver for every state transition:
function hermite(t, p0, p1, m0, m1) {
const t2 = t * t;
const t3 = t2 * t;
return (
(2 * t3 - 3 * t2 + 1) * p0 +
(t3 - 2 * t2 + t) * m0 +
(-2 * t3 + 3 * t2) * p1 +
(t3 - t2) * m1
);
}
Using Cubic Hermite interpolation between predetermined spatial waypoints , the cursor accelerates smoothly towards interaction targets.
When the cursor clicks (e.g., at on the button, or on the play/pause button), it scales down by (scale(0.82)), matching standard desktop operating system feedback.
During dragging phases (such as scrubbing the music timeline from to ):
- The progress bar thumb binds directly to the cursor's horizontal coordinate.
- When dragged past the maximum boundary on the volume slider (), the slider body applies rubber-band resistance, stretching by before snapping back upon release.
Having an ultra-polished standalone HTML file is great, but how do you deliver it inside a modern blog, design portfolio, or documentation site?
Here are the three production-proven patterns:
Because the canvas is designed at , embedding it directly inside responsive blog columns requires dynamic scaling.
We added an auto-fit viewport listener to public/artifacts/ui-morph-engine.html:
function fitViewport() {
const vp = document.getElementById("viewport");
if (!vp) return;
const scale = Math.min(window.innerWidth / 1440, window.innerHeight / 1440);
vp.style.transform = `scale(${scale})`;
vp.style.transformOrigin = "center center";
}
window.addEventListener("resize", fitViewport);
fitViewport();
In your Next.js / MDX page, wrap it in a sleek container:
<div className="relative aspect-square w-full max-w-[720px] mx-auto overflow-hidden rounded-2xl border border-neutral-800 shadow-2xl">
<iframe
src="/artifacts/ui-morph-engine.html"
title="UI Morph Engine"
className="h-full w-full border-0"
loading="lazy"
/>
</div>
For social previews (OpenGraph, Twitter Cards) or native <video> delivery on mobile devices, you can render this engine into an ultra-high-definition video with photorealistic physical motion blur.
Because window.seek(t) is globally exposed, a Playwright script can step through time deterministically at 4 subframes per display frame ():
import { chromium } from "playwright";
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 1440 } });
await page.goto("http://localhost:3000/artifacts/ui-morph-engine.html");
const totalFrames = 60 * 14; // 14 seconds at 60 fps
const subframes = 4;
let frameIndex = 0;
for (let f = 0; f < totalFrames * subframes; f++) {
const t = f / (60 * subframes);
await page.evaluate((time) => window.seek(time), t);
await page.screenshot({ path: `renders/raw_${String(frameIndex++).padStart(6, "0")}.png` });
}
Then blend the subframes using FFmpeg's temporal filter (tmix):
ffmpeg -framerate 240 -i renders/raw_%06d.png \
-vf "tmix=frames=4:weights='1 1 1 1'" \
-r 60 -c:v libvpx-vp9 -b:v 0 -crf 18 -pix_fmt yuv420p \
ui-morph-motion-blurred.webm
This yields broadcast-quality motion blur that is mathematically impossible to achieve with CSS or standard screen recorders.
When engineering deterministic morphing interfaces, keep these non-obvious rules in mind:
- Avoid
will-change: transformon Scaled Containers: Applyingwill-change: transformcauses Chrome and Safari to rasterize the element to an off-screen bitmap at scale 1. When the virtual camera zooms in (scale(1.35)), text and icons will appear blurry. Let the browser composite dynamically without forced texture caching. - Decouple Enter/Exit Opacity Windows: When swapping layers inside a morphing container, cross-fades must have asymmetrical enter and exit windows ( enter, exit). If both layers share the exact boundary time without blur, text glyphs will collide and render illegibly during the transition.
- Exact Boundary Matching for Loop Invariance: For a loop to be truly seamless, the state at and must be numerically identical across all dimensions: container width (), height (), radius (), cursor position (), and cursor velocity (). Any tiny discrepancy produces an annoying stutter every 14 seconds.
The true frontier of digital product design is not static component libraries or pre-baked CSS transition packs. It is mathematical, deterministic motion choreography where timing, physics, audio rhythm, and direct interaction merge into a unified tactile experience.
By treating UI state as a pure function of time and computing physical kinetics through analytical closed-form step responses, we bridge the gap between creative visual artistry and rigorous systems engineering.


