⚠ 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
Tweens and effects
The animation presets one at a time: each takes { duration, delay, easing } and returns a seekable animation. Read FadeAndGrow first, then EasingComparison; the rest are grouped by kind of effect.
Fade and grow
Three shapes enter in different ways: fading in, growing from their center, and spinning in from nothing.
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> );}First scene: animate with a player
Step two of the first-scene tutorial: tracks drive the ring, the radius and the angle, and usePlayer runs the script on the stage clock.
12 collapsed lines
import { derive, draw, sequence, track, valueTo } from "@sophistry/core";import { Arc, Circle, Dot, Line, Stage, Text, usePlayer, useScene,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
const RADIUS = 2.4;const THETA = 1.1;
function Scene() { const theme = useScene().theme; const palette = derive(theme, (t) => t.palette); const { play } = usePlayer(); const drawn = track(0); const theta = track(0); const tip = derive(theta, (theta) => ({ x: RADIUS * Math.cos(theta), y: RADIUS * Math.sin(theta), }));
onSettled(() => { void play( sequence( draw(drawn, { duration: 1.2 }), valueTo(theta, THETA, { duration: 1.6, easing: "smooth" }), ), ); });
return ( <> <Circle radius={RADIUS} stroke={derive(palette, (p) => p.grid)} progress={drawn} /> <Line from={{ x: 0, y: 0 }} to={tip} stroke={derive(palette, (p) => p.series[0])} /> <Arc radius={0.8} angle={theta} stroke={derive(palette, (p) => p.series[1])} /> {/* On the angle's bisector, fading in as the angle opens. */} <Text text="θ" x={derive(theta, (theta) => 1.15 * Math.cos(theta / 2))} y={derive(theta, (theta) => 1.15 * Math.sin(theta / 2))} opacity={derive(theta, (theta) => Math.min(1, theta / THETA))} color={derive(palette, (p) => p.series[1])} /> <Dot center={tip} /> </> );}
export default function FirstSceneAnimated() { return ( <Stage units={10}> <Scene /> </Stage> );}Comparing easings
Five dots cover the same distance in the same time, each with a different easing curve, so you can see how the curves feel.
17 collapsed lines
import { derive, hold, parallel, sequence, track, valueTo,} from "@sophistry/core";import { Dot, Line, Stage, Text, usePlayer, useScene,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
const EASINGS = [ "linear", "inOut", "backOut", "elasticOut", "bounceOut",] as const;const START = -2;// Room past the end for elasticOut, which overshoots by a third or more.const END = 3;
function Race() { const theme = useScene().theme; const { play, signal } = usePlayer(); const xs = EASINGS.map(() => track(START));
onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( parallel( ...xs.map((x, i) => valueTo(x, END, { duration: 2, easing: EASINGS[i] }), ), ), hold(1), ), ); for (const x of xs) x.set(START); await play(hold(0.5)); } })(); });
return ( <> <Line from={{ x: START, y: 2.5 }} to={{ x: START, y: -2.5 }} dash={[0.1, 0.1]} /> <Line from={{ x: END, y: 2.5 }} to={{ x: END, y: -2.5 }} dash={[0.1, 0.1]} /> {EASINGS.map((name, i) => { const y = 2 - i; const color = derive(theme, (t) => t.palette.series[i]); return ( <> <Line from={{ x: START, y }} to={{ x: END, y }} opacity={0.25} /> <Text text={name} x={-4.6} y={y} align="left" fontSize={0.4} color={color} /> <Dot center={derive(xs[i], (x) => ({ x, y }))} radius={0.2} color={color} /> </> ); })} </> );}
export default function EasingComparison() { return ( <Stage units={10}> <Race /> </Stage> );}Manim's rate functions
Six dots make the same trip with Manim's rate functions: a running start, slow into the end, two smooth halves, lingering, exponential decay, and a smooth move squished into the second half.
19 collapsed lines
import { derive, type Easing, hold, parallel, sequence, squish, track, valueTo,} from "@sophistry/core";import { Dot, Line, Stage, Text, usePlayer, useScene,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
const CURVES: { name: string; easing: Easing }[] = [ { name: "runningStart", easing: "runningStart" }, { name: "slowInto", easing: "slowInto" }, { name: "doubleSmooth", easing: "doubleSmooth" }, { name: "lingering", easing: "lingering" }, { name: "exponentialDecay", easing: "exponentialDecay" }, { name: "squish(smooth, 0.5, 1)", easing: squish("smooth", 0.5, 1) },];const START = -1;const END = 5;
function Trips() { const theme = useScene().theme; const { play, signal } = usePlayer(); const xs = CURVES.map(() => track(START));
onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( parallel( ...xs.map((x, i) => valueTo(x, END, { duration: 2.5, easing: CURVES[i].easing }), ), ), hold(1), ), ); for (const x of xs) x.set(START); await play(hold(0.5)); } })(); });
return CURVES.map((curve, i) => { const y = 2.5 - i; const color = derive( theme, (t) => t.palette.series[i % t.palette.series.length], ); return ( <> <Line from={{ x: START, y }} to={{ x: END, y }} opacity={0.25} /> <Text text={curve.name} x={-5.6} y={y} align="left" fontSize={0.32} color={color} /> <Dot center={derive(xs[i], (x) => ({ x, y }))} radius={0.18} color={color} /> </> ); });}
export default function RateFunctions() { return ( <Stage units={12}> <Trips /> </Stage> );}Write and unwrite
Three outlines are drawn one after another with write, held for a moment, then erased in reverse order with unwrite.
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> );}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.
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> );}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.
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> );}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.
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> );}Morph shapes
A circle morphs into a square, a star, and back again.
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> );}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.
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> );}Point moving on a shape
A dot travels around a circle at constant speed by following the circle's outline with moveAlong.
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> );}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.
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> );}Moving angle
One ray swings around a fixed one while an Angle arc and a Text readout follow it, all driven by a single tracked number.
3 collapsed lines
import { derive, forever, sequence, track, valueTo } from "@sophistry/core";import { Angle, Dot, Line, Stage, Text, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
const VERTEX = { x: -1.75, y: -1.5 };const FIXED = { x: 1.75, y: -1.5 };const LENGTH = 3.5;
export default function MovingAngle() { const { play } = usePlayer(); const theta = track(0.4); const tip = derive(theta, (theta) => ({ x: VERTEX.x + LENGTH * Math.cos(theta), y: VERTEX.y + LENGTH * Math.sin(theta), }));
onSettled(() => { void play( forever( sequence( valueTo(theta, 2.4, { duration: 2.5 }), valueTo(theta, 0.4, { duration: 2.5 }), ), ), ); });
return ( <Stage units={10}> <Line from={VERTEX} to={FIXED} /> <Line from={VERTEX} to={tip} /> <Dot center={tip} radius={0.12} /> <Angle vertex={VERTEX} from={FIXED} to={tip} radius={0.9} /> <Text text={derive( theta, (theta) => `θ = ${Math.round((theta * 180) / Math.PI)}°`, )} x={-4.5} align="left" y={2.2} fontSize={0.6} /> </Stage> );}Animated numbers
An Integer, a DecimalNumber and a Variable count up and back down with valueTo; digits keep fixed-width columns so nothing jitters.
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> );}