Skip to content

⚠ Early release: v0.3.2.sophistry is not ready for production use. Until 1.0, any minor release may break the API; expect missing features and bugs too.Stability and versioning

Animation presets

The presets are ready-made animations, grouped here by what they do. All of them come from @sophistry/core. Each takes the track to drive as its first argument (or any animatable), plus the same { duration, delay, easing } options (see Options every preset accepts), and returns a seekable animation you run with usePlayer() in a component or scene.play / scene.timeline without a framework. Bind the same track to the node’s prop (progress={drawn}, opacity={opacity}), and the preset animates the node with no framework work per frame. To combine them, see Composing animations.

Reveals that draw a shape’s outline. Bind the track to a shape’s progress prop.

Preset What it does
draw(progress) Draws the outline from 0 to 1.
erase(progress) Erases it.
write(progresses, { lag, lagRatio }) draw across several tracks, staggered. lagRatio wins if both are given.
unwrite(progresses, { lag, reverse }) Staggered erase, last stroke first by default.
drawBorderThenFill(progress, fillOpacity) Traces the outline (65%), then fades the fill in (35%).

draw is an arc-length reveal: the renderer measures the shape’s polylines and trims them to the current progress. A shape’s polylines share one reveal budget, spent in order, so a multi-part shape draws part by part. An arrow’s shaft finishes before its head starts. <Text> is the exception: canvas cannot trim a glyph outline, so text is written glyph by glyph instead, each glyph fading in whole. For maths, @sophistry/text turns LaTeX into real geometry that does reveal stroke by stroke (see Math and LaTeX).

Write and unwrite

Three outlines are drawn one after another with write, held for a moment, then erased in reverse order with unwrite.

WriteAndErase.tsx
10 collapsed lines
import { hold, track, unwrite, write } from "@sophistry/core";
import {
Circle,
Polygon,
Square,
Stage,
Text,
usePlayer,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
export default function WriteAndErase() {
const { play, signal } = usePlayer();
const drawn = [track(0), track(0), track(0)];
const caption = track("write");
onSettled(() => {
void (async () => {
while (!signal.aborted) {
caption.set("write");
await play(write(drawn, { lag: 0.5, duration: 1 }));
await play(hold(1));
caption.set("unwrite");
await play(unwrite(drawn, { lag: 0.5, duration: 1 }));
await play(hold(0.6));
}
})();
});
return (
<Stage units={10}>
<Circle center={{ x: -3.5, y: 0 }} radius={1.2} progress={drawn[0]} />
<Square size={2.4} progress={drawn[1]} />
<Polygon
center={{ x: 3.5, y: 0 }}
radius={1.4}
sides={3}
progress={drawn[2]}
/>
<Text text={caption} y={-2.4} />
</Stage>
);
}
Preset What it does
fadeIn(opacity), fadeOut(opacity), fadeTo(opacity, value) Opacity tweens.
fadeInFrom(opacity, position, offset), fadeOutTo(...) Fade while drifting in from, or out toward, an offset.
growFromCenter(scale) Swells from nothing about the shape’s center.
growFromPoint(scale, position, from) Grows while travelling from a point.
growFromEdge(scale, position, bounds, direction) Grows out of one edge.
shrinkToCenter(scale) The inverse of growFromCenter.
spinInFromNothing(scale, rotation) Grows while spinning in.

growFromCenter is also Manim’s GrowArrow: set origin={tail} on an <Arrow> and the scale pivots on the tail, inflating a small complete arrow, head and all. The grow presets snap back to their resting scale if a run is aborted midway, so a cancelled script never leaves a shape stuck at half size.

Fade and grow

Three shapes enter in different ways: fading in, growing from their center, and spinning in from nothing.

FadeAndGrow.tsx
20 collapsed lines
import {
fadeIn,
fadeOut,
growFromCenter,
hold,
parallel,
shrinkToCenter,
spinInFromNothing,
track,
} from "@sophistry/core";
import { starPolygon } from "@sophistry/core/geometry";
import {
Circle,
Polygon,
Square,
Stage,
Text,
usePlayer,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
export default function FadeAndGrow() {
const { play, signal } = usePlayer();
const opacity = track(0);
const grow = track(1);
const spin = track(1);
const turn = track(0);
onSettled(() => {
void (async () => {
while (!signal.aborted) {
await play(
parallel(
fadeIn(opacity),
growFromCenter(grow),
spinInFromNothing(spin, turn),
),
);
await play(hold(1.2));
await play(
parallel(
fadeOut(opacity),
shrinkToCenter(grow),
shrinkToCenter(spin),
),
);
await play(hold(0.6));
// Back to full size only now, just before they grow again: reset
// before the hold, they would pop back for its length.
grow.set(1);
spin.set(1);
}
})();
});
return (
<Stage units={12}>
<Circle center={{ x: -4, y: 0 }} radius={1} opacity={opacity} />
<Square center={{ x: 0, y: 0 }} size={1.8} scale={grow} />
<Polygon
points={starPolygon(4, 0, 1.1, 0.5, 5)}
scale={spin}
rotation={turn}
/>
<Text text="fadeIn" x={-4} y={-2} />
<Text text="growFromCenter" x={0} y={-2} />
<Text text="spinInFromNothing" x={4} y={-2} />
</Stage>
);
}
Preset What it does
moveTo(position, point) Moves a point track to a target.
moveBy(position, delta) Moves by an offset from wherever it is when it starts.
moveAlong(position, polyline) Follows a path at constant speed.
rotateTo(rotation, radians), rotateBy(rotation, radians) Absolute and relative rotation.
scaleTo(scale, value) Scale tween.
colorTo(color, target, { colorSpace }) Color tween; colorSpace: "oklch" blends perceptually.
valueTo(value, target) Any number track: the base case the others build on.
springTo(target, to, spring) Any value, moved by a spring: seekable, its duration is the settle time, and it can overshoot. See Springs.

rotateTo, scaleTo and fadeTo are literally valueTo under another name. The target of valueTo can be a function of the starting value, such as valueTo(x, (v) => v + 5).

Point moving on a shape

A dot travels around a circle at constant speed by following the circle's outline with moveAlong.

PointMovingOnShapes.tsx
4 collapsed lines
import { forever, moveAlong, trackPoint } from "@sophistry/core";
import { circlePolyline } from "@sophistry/core/geometry";
import { Circle, Dot, Line, Stage, usePlayer } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
const RING = circlePolyline(0, 0, 2.2);
export default function PointMovingOnShapes() {
const { play } = usePlayer();
const dot = trackPoint(2.2, 0);
onSettled(() => {
void play(forever(moveAlong(dot, RING, { duration: 4 })));
});
return (
<Stage units={9}>
<Circle radius={2.2} />
<Line from={{ x: 0, y: 0 }} to={dot} dash={[0.15, 0.1]} />
<Dot center={dot} radius={0.15} />
</Stage>
);
}

moveTo and moveBy travel in a straight line unless you pass pathArc: the point swings round an arc that turns through that many radians on the way (Manim’s path_arc), counter-clockwise for positive. Math.PI is a half circle, which is how two things swap places without passing through each other. The same option on morph and morphPath carries every vertex of a shape along its own arc, which is Manim’s ClockwiseTransform (-Math.PI) and CounterclockwiseTransform (Math.PI). The path on its own is pathAlongArc(angle) in @sophistry/core/geometry.

To show where something has been, put a <TracedPath point={position} /> beside it, bound to the same point track. It remembers the point against time (the stage clock’s, by default), and dissipatingTime keeps only the recent stretch. It is safe to scrub: bind a timeline’s time as time={tl.time}, and seeking back shortens the trail to match.

Arcs, trails and changing speed

Two dots swap places along half-circle arcs instead of straight lines, slowing right down as they pass each other, and each leaves a fading trail.

ArcsTrailsAndSpeed.tsx
17 collapsed lines
import {
changeSpeed,
derive,
hold,
moveTo,
parallel,
sequence,
trackPoint,
} from "@sophistry/core";
import {
Dot,
Stage,
TracedPath,
usePlayer,
useScene,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
const LEFT = { x: -3, y: 0 };
const RIGHT = { x: 3, y: 0 };
/** Normal speed, a crawl around the middle, normal again. */
const SLOW_MIDDLE = { 0.35: 1, 0.5: 0.2, 0.65: 1 };
function Swap() {
const theme = useScene().theme;
const first = derive(theme, (t) => t.palette.series[0]);
const second = derive(theme, (t) => t.palette.series[1]);
const { play, signal } = usePlayer();
const a = trackPoint(LEFT.x, LEFT.y);
const b = trackPoint(RIGHT.x, RIGHT.y);
const swap = (to: { a: typeof LEFT; b: typeof LEFT }) =>
changeSpeed(
parallel(
moveTo(a, to.a, { duration: 1.5, pathArc: Math.PI }),
moveTo(b, to.b, { duration: 1.5, pathArc: Math.PI }),
),
SLOW_MIDDLE,
);
onSettled(() => {
void (async () => {
while (!signal.aborted) {
await play(
sequence(
swap({ a: RIGHT, b: LEFT }),
hold(0.5),
swap({ a: LEFT, b: RIGHT }),
hold(0.5),
),
);
}
})();
});
return (
<>
<TracedPath point={a} dissipatingTime={1.2} stroke={first} />
<TracedPath point={b} dissipatingTime={1.2} stroke={second} />
<Dot center={a} radius={0.2} color={first} />
<Dot center={b} radius={0.2} color={second} />
</>
);
}
export default function ArcsTrailsAndSpeed() {
return (
<Stage units={12}>
<Swap />
</Stage>
);
}

These drive a shape’s points track (one polyline or several) by sending each point somewhere. A curving map bends the space between two vertices too, so long edges are split first, into pieces a sixty-fourth of the shape’s size unless you set segmentLength.

Preset What it does
homotopy(points, (p, t) => …) Flows every point through a family of maps over time; h(p, 0) should be p. Manim’s Homotopy (3 s by default).
applyFunction(points, f) Sends every point to f(p) and leaves it there (ApplyPointwiseFunction). pathArc curves the trip.
applyComplexFunction(points, f) The plane as complex numbers, each point sent to f(z) along an arc turning through the argument of f(1), as Manim’s does.
phaseFlow(points, f, { virtualTime }) Every point flows along the vector field f for virtualTime (Manim’s PhaseFlow). Paths are integrated once on entry, so it scrubs exactly.

For a linear map use <LinearTransform> instead, which is exact and costs nothing (see Coordinate systems).

Squaring the complex plane

A grid of lines is sent through z ↦ z²: straight lines bend into parabolas, and right angles stay right angles.

ComplexSquaring.tsx
10 collapsed lines
import {
applyComplexFunction,
derive,
hold,
sequence,
track,
} from "@sophistry/core";
import type { Polyline } from "@sophistry/core/geometry";
import { Line, Path, Stage, usePlayer, useScene } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
/** Horizontal and vertical lines over 0.3 ≤ x ≤ 1.5, −0.6 ≤ y ≤ 0.6. */
function grid(): Polyline[] {
const lines: Polyline[] = [];
for (let i = 0; i <= 6; i++) {
const y = -0.6 + i * 0.2;
lines.push([
{ x: 0.3, y },
{ x: 1.5, y },
]);
const x = 0.3 + i * 0.2;
lines.push([
{ x, y: -0.6 },
{ x, y: 0.6 },
]);
}
return lines;
}
const square = ({ re, im }: { re: number; im: number }) => ({
re: re * re - im * im,
im: 2 * re * im,
});
function Squaring() {
const accent = derive(useScene().theme, (theme) => theme.palette.accent);
const { play, signal } = usePlayer();
const lines = track(grid());
onSettled(() => {
void (async () => {
while (!signal.aborted) {
lines.set(grid());
await play(
sequence(
hold(0.6),
applyComplexFunction(lines, square, { duration: 2.5 }),
hold(1.2),
),
);
}
})();
});
return (
<>
<Line from={{ x: -1, y: 0 }} to={{ x: 3, y: 0 }} opacity={0.35} />
<Line from={{ x: 0, y: -2 }} to={{ x: 0, y: 2 }} opacity={0.35} />
<Path points={lines} stroke={accent} strokeWidth={0.015} />
</>
);
}
export default function ComplexSquaring() {
return (
<Stage units={7.6} center={{ x: 1, y: 0 }}>
<Squaring />
</Stage>
);
}

A pendulum's phase flow

A disc of starting states flows along a pendulum's phase portrait: near the bottom it circles round, and it stretches into a thin arc as the swings drift out of step.

PendulumPhaseFlow.tsx
10 collapsed lines
import { derive, hold, phaseFlow, sequence, track } from "@sophistry/core";
import { circlePolyline } from "@sophistry/core/geometry";
import {
Path,
Stage,
StreamLines,
usePlayer,
useScene,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
/** Angle along x, angular velocity along y. */
const pendulum = ({ x, y }: { x: number; y: number }) => ({
x: y,
y: -Math.sin(x),
});
const start = () => circlePolyline(-1.6, 0, 0.45);
function Flow() {
const theme = useScene().theme;
const { play, signal } = usePlayer();
const disc = track(start());
onSettled(() => {
void (async () => {
while (!signal.aborted) {
disc.set(start());
await play(
sequence(
hold(0.5),
phaseFlow(disc, pendulum, { virtualTime: 6, duration: 4 }),
hold(1),
),
);
}
})();
});
return (
<>
<StreamLines
function={pendulum}
xRange={[-5, 5]}
yRange={[-2.8, 2.8]}
opacity={0.35}
/>
<Path
points={disc}
closed
fill={derive(theme, (t) => t.palette.accent)}
fillOpacity={0.6}
stroke={derive(theme, (t) => t.palette.foreground)}
strokeWidth={0.02}
/>
</>
);
}
export default function PendulumPhaseFlow() {
return (
<Stage units={10}>
<Flow />
</Stage>
);
}

Manim’s emphasis family animates around a shape without moving it.

Preset What it does
indicate(scale) Swells and returns, optionally flashing a color.
pulse(scale) A gentle there-and-back scale; good inside forever.
flash(radius, opacity) A ring that expands and fades.
wiggle(rotation) Shakes back and forth.
circumscribe(progress) Draws a box around something, then erases it.

Emphasis effects

Four ways to draw the eye in turn: indicate swells a dot, wiggle shakes a square, flash sends out a ring, circumscribe boxes a label.

EmphasisEffects.tsx
19 collapsed lines
import {
circumscribe,
flash,
hold,
indicate,
sequence,
track,
wiggle,
} from "@sophistry/core";
import {
Circle,
Dot,
Rect,
Square,
Stage,
Text,
usePlayer,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
export default function EmphasisEffects() {
const { play, signal } = usePlayer();
const scale = track(1);
const rotation = track(0);
const radius = track(0.4);
const opacity = track(0);
const drawn = track(0);
onSettled(() => {
void (async () => {
while (!signal.aborted) {
await play(
sequence(
indicate(scale, { factor: 1.6 }),
wiggle(rotation, { amplitude: 0.3 }),
flash(radius, opacity, { from: 0.4, to: 1.2 }),
circumscribe(drawn),
hold(1),
),
);
}
})();
});
return (
<Stage units={12}>
<Dot center={{ x: -4.2, y: 0 }} radius={0.5} scale={scale} />
<Square center={{ x: -1.4, y: 0 }} size={1.2} rotation={rotation} />
<Dot center={{ x: 1.4, y: 0 }} radius={0.15} />
<Circle center={{ x: 1.4, y: 0 }} radius={radius} opacity={opacity} />
<Text text="emphasis" x={4.2} fontSize={0.45} />
<Rect
center={{ x: 4.2, y: 0 }}
width={3.2}
height={1.2}
progress={drawn}
/>
<Text text="indicate" x={-4.2} y={-2} />
<Text text="wiggle" x={-1.4} y={-2} />
<Text text="flash" x={1.4} y={-2} />
<Text text="circumscribe" x={4.2} y={-2} />
</Stage>
);
}

The rest of Manim’s indication family. Each one also leaves its tracks at rest when it finishes.

Preset What it does
focusOn(radius, opacity) A wide, faint disc closes in on a point, then vanishes. Start the disc wide and at opacity 0.
blink(opacity) Hides and shows again, blinks times (timeOn, timeOff, hideAtEnd).
showPassingFlash(progress) A short stretch of stroke runs along a path and off its end.
applyWave(points) A wave runs across a shape’s points and lets them settle back.

showPassingFlash only drives a 0..1 track. passingFlash(length, t, width) turns that into the stroke’s dash, dashOffset and visible, for a copy of the path drawn in a highlight color. length is the path’s arc length, measure(points).total from @sophistry/core/geometry. Derive each prop from the progress track, as in dash={derive(flash, (t) => passingFlash(length, t).dash)}, so they follow it with no framework work. A dash starts over on each ring of a shape, so on a shape with several rings, each carries its own flash. applyWave drives the points track of a Path or Polygram, either one polyline or several. Long straight edges are split for the duration so they can bend, and the original points come back at the end. direction, amplitude, timeWidth and ripples shape the wave.

Indication effects

Four more ways to point at something: a spotlight closes in, a dot blinks, a flash runs along a curve, and a wave ripples through a bar.

IndicationEffects.tsx
23 collapsed lines
import {
applyWave,
blink,
derive,
focusOn,
hold,
passingFlash,
sequence,
showPassingFlash,
track,
} from "@sophistry/core";
import type { Polyline } from "@sophistry/core/geometry";
import { measure, rectPolyline } from "@sophistry/core/geometry";
import {
Circle,
Dot,
Path,
Stage,
Text,
usePlayer,
useScene,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
const curve: Polyline = Array.from({ length: 41 }, (_, i) => {
const x = -1.4 + (i / 40) * 2.8;
return { x: x + 1.6, y: 0.8 * Math.sin(x * 2.2) };
});
const curveLength = measure(curve).total;
function Effects() {
const palette = derive(useScene().theme, (t) => t.palette);
const { play, signal } = usePlayer();
const spot = track(6);
const spotOpacity = track(0);
const shown = track(1);
const flash = track(0);
const bar = track(rectPolyline(3.6, -0.25, 2.8, 0.5));
const flashed = derive(flash, (t) => passingFlash(curveLength, t, 0.25));
onSettled(() => {
void (async () => {
while (!signal.aborted) {
await play(
sequence(
focusOn(spot, spotOpacity, { duration: 1.5 }),
blink(shown, { blinks: 3, timeOn: 0.2, timeOff: 0.2 }),
showPassingFlash(flash, { duration: 1.2 }),
applyWave(bar, { amplitude: 0.5, duration: 1.5 }),
hold(1),
),
);
}
})();
});
return (
<>
<Circle
center={{ x: -4.5, y: 0 }}
radius={spot}
fill={derive(palette, (p) => p.foreground)}
stroke="none"
opacity={spotOpacity}
/>
<Dot center={{ x: -4.5, y: 0 }} radius={0.2} />
<Dot center={{ x: -1.5, y: 0 }} radius={0.35} opacity={shown} />
<Path points={curve} opacity={0.35} />
<Path
points={curve}
stroke={derive(palette, (p) => p.highlight)}
strokeWidth={0.08}
dash={derive(flashed, (f) => f.dash)}
dashOffset={derive(flashed, (f) => f.dashOffset)}
visible={derive(flashed, (f) => f.visible)}
/>
<Path points={bar} closed fill={derive(palette, (p) => p.accent)} />
<Text text="focusOn" x={-4.5} y={-2} />
<Text text="blink" x={-1.5} y={-2} />
<Text text="showPassingFlash" x={1.6} y={-2} />
<Text text="applyWave" x={5} y={-2} />
</>
);
}
export default function IndicationEffects() {
return (
<Stage units={14}>
<Effects />
</Stage>
);
}

For emphasis that just keeps going, <AnimatedBoundary points={…} /> runs a colored stroke round an outline, a new color each cycle (colors, cycleRate), drawing every other cycle backwards while the previous one thins away. It is a component rather than an animation: it reads the stage clock’s time, or a time you bind, so it runs with no play at all and scrubs with a timeline’s time. Give it the outline of the shape it surrounds.

Animated boundary

A stroke keeps running round a box, a new colour each cycle, while the last one thins away underneath: ambient emphasis that needs no animation.

AnimatedBoundaryHighlight.tsx
2 collapsed lines
import { rectPolyline } from "@sophistry/core/geometry";
import { AnimatedBoundary, Stage, Text } from "@sophistry/solidjs";
export default function AnimatedBoundaryHighlight() {
return (
<Stage units={8}>
<Text text="the key step" fontSize={0.5} />
<AnimatedBoundary
points={rectPolyline(-2, -0.6, 4, 1.2, 0.2)}
strokeWidth={0.06}
cycleRate={0.6}
/>
</Stage>
);
}
Preset What it does
morph(polyline, target, { closed, pathArc }) Interpolates a polyline track into another shape with closed-ring correspondence, so shapes do not spin en route. pathArc swings it round an arc.
morphPath(rings, fromSvg, toSvg) Morphs between two SVG path strings into a track of rings (Polyline[]). Holes stay holes, and pieces with no partner grow or shrink.
morphCurve(curve, target) Morphs a curve path.
morphWith(polyline, interpolator) Bring your own interpolator.
<TransformMatchingShapes> Pairs groups of shapes by similarity (below).
4 collapsed lines
import { morph, track } from "@sophistry/core";
import { circlePolyline, rectPolyline } from "@sophistry/core/geometry";
import { Polygon, Stage, usePlayer } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
function Morphing() {
const shape = track(circlePolyline(0, 0, 2));
const player = usePlayer();
onSettled(() => {
void player.play(morph(shape, rectPolyline(-1.8, -1.8, 3.6, 3.6), { closed: true }));
});
return <Polygon points={shape} />;
}
export const Scene = () => (
<Stage units={8}>
<Morphing />
</Stage>
);

Morph shapes

A circle morphs into a square, a star, and back again.

MorphShapes.tsx
8 collapsed lines
import { hold, morph, track } from "@sophistry/core";
import {
circlePolyline,
rectPolyline,
starPolygon,
} from "@sophistry/core/geometry";
import { Polygon, Stage, usePlayer } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
const CIRCLE = circlePolyline(0, 0, 2);
const SQUARE = rectPolyline(-1.8, -1.8, 3.6, 3.6);
const STAR = starPolygon(0, 0, 2, 0.9, 5);
export default function MorphShapes() {
const { play, signal } = usePlayer();
const shape = track(CIRCLE);
onSettled(() => {
void (async () => {
while (!signal.aborted) {
for (const to of [SQUARE, STAR, CIRCLE]) {
await play(morph(shape, to, { closed: true, duration: 1.2 }));
await play(hold(0.4));
}
}
})();
});
return (
<Stage units={9}>
<Polygon points={shape} />
</Stage>
);
}

<MathTransform> pairs glyphs by parsing TeX. Ordinary shapes have nothing to parse, so <TransformMatchingShapes> pairs them by point-cloud similarity instead, which is Manim’s TransformMatchingShapes. You drive its blend from 0 to 1 with a track:

4 collapsed lines
import { track, valueTo } from "@sophistry/core";
import type { ShapePart } from "@sophistry/core/geometry";
import { Stage, TransformMatchingShapes, usePlayer } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
const from: ShapePart[] = [
{ polylines: [[{ x: -1, y: -1 }, { x: 1, y: -1 }, { x: 1, y: 1 }, { x: -1, y: 1 }]] },
];
const to: ShapePart[] = [
{ polylines: [[{ x: -1, y: -1 }, { x: 1, y: -1 }, { x: 0, y: 1 }]] },
];
function Matching() {
const blend = track(0);
const player = usePlayer();
onSettled(() => void player.play(valueTo(blend, 1, { duration: 1.5 })));
return <TransformMatchingShapes from={from} to={to} blend={blend} />;
}
export const Scene = () => (
<Stage units={6}>
<Matching />
</Stage>
);

Matching has two phases. Correspondence decides which from shape becomes which to shape. Then each matched pair is morphed, so shapes with different vertex counts still resample cleanly. Unmatched shapes cross-fade. The component renders the result directly, a group of paths that changes frame to frame as blend moves.

Matching ignores position and size, and unrelated shapes with similar vertex counts and areas (a hexagon and a heptagon) can still pair. Set maxCost to refuse pairs worse than a threshold; those shapes fade instead.

Matching shapes

A square and a circle become a larger circle and a long bar. TransformMatchingShapes pairs each shape with the one it most resembles, so nothing crosses over.

MatchingShapes.tsx
5 collapsed lines
import { hold, sequence, track, valueTo } from "@sophistry/core";
import type { ShapePart } from "@sophistry/core/geometry";
import { circlePolyline, rectPolyline } from "@sophistry/core/geometry";
import { Stage, TransformMatchingShapes, usePlayer } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
const FROM: ShapePart[] = [
{ polylines: [rectPolyline(-3.5, -1, 2, 2)] },
{ polylines: [circlePolyline(2.5, 0, 1)] },
];
const TO: ShapePart[] = [
{ polylines: [circlePolyline(-2.5, 0, 1.4)] },
{ polylines: [rectPolyline(1, -0.5, 3.5, 1)] },
];
export default function MatchingShapes() {
const { play, signal } = usePlayer();
const blend = track(0);
onSettled(() => {
void (async () => {
while (!signal.aborted) {
await play(
sequence(
hold(0.8),
valueTo(blend, 1, { duration: 1.6 }),
hold(0.8),
valueTo(blend, 0, { duration: 1.6 }),
),
);
}
})();
});
return (
<Stage units={10}>
<TransformMatchingShapes from={FROM} to={TO} blend={blend} />
</Stage>
);
}

Integer, DecimalNumber and Variable are numbers as scene objects: one node per character, tabular columns so nothing shimmers, and value as an ordinary prop driven by valueTo.

3 collapsed lines
import { track, valueTo } from "@sophistry/core";
import { Integer, Stage, usePlayer } from "@sophistry/solidjs";
import { onSettled } from "solid-js";
function Counter() {
const count = track(0);
const player = usePlayer();
onSettled(() => void player.play(valueTo(count, 2048, { duration: 2 })));
return <Integer value={count} fontSize={1.2} minIntegerDigits={4} />;
}
export const Scene = () => (
<Stage units={10}>
<Counter />
</Stage>
);

value is bound to the track, so nothing in Solid runs while the number counts.

Animated numbers

An Integer, a DecimalNumber and a Variable count up and back down with valueTo; digits keep fixed-width columns so nothing jitters.

AnimatedNumbers.tsx
10 collapsed lines
import { hold, parallel, sequence, track, valueTo } from "@sophistry/core";
import {
DecimalNumber,
Integer,
Stage,
Text,
usePlayer,
Variable,
} from "@sophistry/solidjs";
import { onSettled } from "solid-js";
export default function AnimatedNumbers() {
const { play, signal } = usePlayer();
const count = track(0);
const speed = track(0);
const price = track(0);
onSettled(() => {
void (async () => {
while (!signal.aborted) {
await play(
sequence(
parallel(
valueTo(count, 12345, { duration: 2 }),
valueTo(speed, 98.6, { duration: 2 }),
valueTo(price, 9.5, { duration: 2 }),
),
hold(1),
parallel(
valueTo(count, 0, { duration: 1.5 }),
valueTo(speed, 0, { duration: 1.5 }),
valueTo(price, 0, { duration: 1.5 }),
),
hold(0.6),
),
);
}
})();
});
return (
<Stage units={10}>
<Text text="Integer" x={-4.5} y={1.6} align="left" fontSize={0.4} />
<Integer
value={count}
x={4.5}
y={1.6}
align="right"
fontSize={0.8}
groupDigits
minIntegerDigits={6}
/>
<Text text="DecimalNumber" x={-4.5} y={0} align="left" fontSize={0.4} />
<DecimalNumber
value={speed}
x={4.5}
y={0}
align="right"
fontSize={0.8}
decimalPlaces={1}
unit=" m/s"
minIntegerDigits={2}
/>
<Text text="Variable" x={-4.5} y={-1.6} align="left" fontSize={0.4} />
<Variable label="price" value={price} x={-0.5} y={-1.6} fontSize={0.8} />
</Stage>
);
}