⚠ 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
Basic concepts
Start here. These examples cover the pieces every scene is made of: a <Stage>, shapes styled by the active theme, layout helpers that place nodes by their measured bounds, a coordinate plane, and a first draw() and moveTo() driving tracks passed as props. Components come from @sophistry/solidjs; tracks, animations and layout helpers from @sophistry/core. Each is short enough to read in one sitting, and every one runs live and shows its full source.
The first three (ShapesGallery, FirstSceneShapes, UnitCircle) are the best starting points. FirstScene* examples are the steps of the first scene tutorial, so you can compare each step with its result.
Shapes gallery
The basic shapes, each styled with stroke, fill and opacity; colors come from the active theme.
10 collapsed lines
import { derive } from "@sophistry/core";import { Arrow, Circle, Polygon, Rect, Stage, Star, useScene,} from "@sophistry/solidjs";
function Shapes() { const theme = useScene().theme; const series = (i: number) => derive(theme, (t) => t.palette.series[i]);
return ( <> <Circle center={{ x: -4.4, y: 0 }} radius={0.9} stroke={series(0)} fill={series(0)} /> <Rect center={{ x: -2.2, y: 0 }} width={1.8} height={1.4} cornerRadius={0.2} stroke={series(1)} fill={series(1)} fillOpacity={0.35} /> <Polygon sides={6} radius={1} stroke={series(2)} fill={series(2)} /> <Star center={{ x: 2.2, y: 0 }} outerRadius={1} stroke={series(3)} fill={series(3)} fillOpacity={0.5} strokeWidth={0.08} /> <Arrow from={{ x: 3.6, y: -0.8 }} to={{ x: 5.2, y: 0.8 }} stroke={series(4)} strokeWidth={0.08} /> </> );}
export default function ShapesGallery() { return ( <Stage units={12}> <Shapes /> </Stage> );}First scene: shapes and labels
Step one of the first-scene tutorial: a ring, a radius, an angle arc and a dot, with a label placed next to the dot by its measured bounds.
11 collapsed lines
import type { SceneNode } from "@sophistry/core";import { derive, nextTo, UR } from "@sophistry/core";import { Arc, Circle, Dot, Line, Stage, Text, useScene,} from "@sophistry/solidjs";
const R = 2.4;const THETA = 0.9;
function Figure() { const theme = useScene().theme; const grid = derive(theme, (t) => t.palette.grid); const first = derive(theme, (t) => t.palette.series[0]); const second = derive(theme, (t) => t.palette.series[1]); const tip = { x: R * Math.cos(THETA), y: R * Math.sin(THETA) }; let dot!: SceneNode;
return ( <> <Circle radius={R} stroke={grid} /> <Line from={{ x: 0, y: 0 }} to={tip} stroke={first} /> <Arc radius={0.8} angle={THETA} stroke={second} /> <Text text="θ" x={1.15} y={0.35} color={second} /> <Dot ref={(node) => (dot = node)} center={tip} /> <Text text="P" ref={(name) => name.set("place", nextTo(name.localBounds(), dot.bounds(), UR)) } /> </> );}
export default function FirstSceneShapes() { return ( <Stage units={10}> <Figure /> </Stage> );}Unit circle
Draw a circle with draw(), then send a dot around it with moveTo().
3 collapsed lines
import { draw, moveTo, track, trackPoint } from "@sophistry/core";import { Circle, Dot, Stage, Text, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
export default function UnitCircle() { const { play, signal } = usePlayer(); const drawn = track(0); const dot = trackPoint(2, 0);
onSettled(() => { void (async () => { await play(draw(drawn, { duration: 1.5 })); while (!signal.aborted) { for (const at of [ { x: 0, y: 2 }, { x: -2, y: 0 }, { x: 0, y: -2 }, { x: 2, y: 0 }, ]) { // A quarter-turn arc, at a steady speed: round the circle, not // across its chords, without stopping at each quarter. await play( moveTo(dot, at, { duration: 1, pathArc: Math.PI / 2, easing: "linear", }), ); } } })(); });
return ( <Stage units={10}> <Circle center={{ x: 0, y: 0 }} radius={2} progress={drawn} /> {/* Both arrive with the circle they belong to. */} <Dot center={dot} opacity={drawn} /> <Text text="unit circle" y={0} opacity={drawn} /> </Stage> );}Group transforms
A Group moves, rotates and scales everything inside it at once; here two scaled copies of a small figure turn together.
10 collapsed lines
import { hold, track, valueTo } from "@sophistry/core";import { Circle, Group, Line, Square, Stage, usePlayer,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
function Figure() { return ( <> <Square size={1.2} /> <Circle center={{ x: 1.2, y: 0 }} radius={0.3} /> <Line from={{ x: 0.6, y: 0 }} to={{ x: 0.9, y: 0 }} /> </> );}
export default function GroupTransforms() { const { play, signal } = usePlayer(); const angle = track(0);
onSettled(() => { void (async () => { while (!signal.aborted) { await play(valueTo(angle, Math.PI * 2, { duration: 4 })); angle.set(0); await play(hold(0.5)); } })(); });
return ( <Stage units={10}> <Group x={-2.8} rotation={angle}> <Figure /> </Group> <Group x={2.3} rotation={angle} scale={1.6} opacity={0.6}> <Figure /> </Group> </Stage> );}Labels and positioning
Line three shapes up with arrange(), then hang a caption beneath one with nextTo(), using each shape's measured bounds.
4 collapsed lines
import type { Placement, SceneNode } from "@sophistry/core";import { arrange, DOWN, nextTo, RIGHT } from "@sophistry/core";import { Circle, Square, Stage, Star, Text } from "@sophistry/solidjs";import { onSettled } from "solid-js";
/** Any node with a `place` prop: shapes and labels. */type Placeable = SceneNode<{ place?: Placement }>;
export default function LabelsAndPositioning() { // The nodes are the handles: once they exist, measure them and place them. const shapes: Placeable[] = []; let caption!: Placeable; onSettled(() => { const row = arrange( shapes.map((shape) => shape.localBounds()), RIGHT, { gap: 0.8 }, ); for (const [i, shape] of shapes.entries()) shape.set("place", row[i]); caption.set( "place", nextTo(caption.localBounds(), shapes[1].bounds(), DOWN, { gap: 0.6 }), ); });
return ( <Stage units={10}> <Circle ref={(node) => shapes.push(node)} radius={0.7} /> <Square ref={(node) => shapes.push(node)} size={1.4} /> <Star ref={(node) => shapes.push(node)} outerRadius={0.8} /> <Text ref={(node) => (caption = node)} text="arrange(RIGHT), then nextTo(DOWN)" /> </Stage> );}A diagram laid out by placement
Three boxes in a row, captions under each, arrows between them, a frame around the lot and a title pinned to the corner. No coordinates are typed by hand.
27 collapsed lines
import type { ArrowProps, Placement, SceneNode, SurroundingRectangleProps,} from "@sophistry/core";import { arrange, DOWN, derive, LEFT, nextTo, ORIGIN, RIGHT, toCorner, UL, unionBounds,} from "@sophistry/core";import { Arrow, Rect, Stage, SurroundingRectangle, Text, useScene,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
const STEPS = ["parse", "transform", "render"];
/** Any node with a `place` prop: shapes and labels. */type Placeable = SceneNode<{ place?: Placement }>;
function Diagram() { const scene = useScene(); const series = derive(scene.theme, (theme) => theme.palette.series); const muted = derive(scene.theme, (theme) => theme.palette.muted); const border = derive(scene.theme, (theme) => theme.palette.border);
// The nodes are the handles: once they exist, measure them and place them. const boxes: Placeable[] = []; const captions: Placeable[] = []; const arrows: SceneNode<ArrowProps>[] = []; let frame!: SceneNode<SurroundingRectangleProps>; let title!: Placeable;
onSettled(() => { const row = arrange( boxes.map((box) => box.localBounds()), RIGHT, { gap: 1.2 }, ); for (const [i, box] of boxes.entries()) { box.set("place", row[i]); const caption = captions[i]; caption.set( "place", nextTo(caption.localBounds(), box.bounds(), DOWN, { gap: 0.3 }), ); } // Another shape's bounds may feed geometry props (arrow ends, a frame). for (const [i, arrow] of arrows.entries()) { arrow.update({ from: boxes[i].pointAt(RIGHT) ?? ORIGIN, to: boxes[i + 1].pointAt(LEFT) ?? ORIGIN, }); } frame.set( "target", unionBounds(...[...boxes, ...captions].map((node) => node.bounds())), ); title.set( "place", toCorner(title.localBounds(), scene.frame.peek(), UL, { margin: 0.4 }), ); });
return ( <> {STEPS.map((step, i) => ( <> <Rect ref={(node) => boxes.push(node)} width={2.2} height={1.2} cornerRadius={0.2} stroke={derive(series, (s) => s[i])} fill={derive(series, (s) => s[i])} fillOpacity={0.25} /> <Text ref={(node) => captions.push(node)} text={step} fontSize={0.34} /> </> ))} {[0, 1].map(() => ( <Arrow ref={(node) => arrows.push(node)} from={ORIGIN} to={ORIGIN} strokeWidth={0.06} stroke={muted} /> ))} <SurroundingRectangle ref={(node) => (frame = node)} target={null} padding={0.4} cornerRadius={0.2} dash={[0.15, 0.1]} stroke={border} /> <Text ref={(node) => (title = node)} text="A tiny pipeline" fontSize={0.4} fontWeight={600} /> </> );}
export default function LabelledDiagram() { return ( <Stage units={12}> <Diagram /> </Stage> );}Coordinate plane
Axes map data coordinates to scene units: plot a function inside them, and use coordsToPoint() to place a point at (2, 4).
9 collapsed lines
import type { SceneNode } from "@sophistry/core";import { coordsOf, ORIGIN } from "@sophistry/core";import { Axes, DashedLine, FunctionGraph, LabeledDot, Stage,} from "@sophistry/solidjs";
export default function CoordinatePlane() { // The node is the handle; coordsOf reads the system it publishes. let axes!: SceneNode; const toScene = (x: number, y: number) => coordsOf(axes)?.coordsToPoint(x, y) ?? ORIGIN;
return ( <Stage units={10}> <Axes ref={(node) => (axes = node)} xRange={[-3, 3, 1]} yRange={[0, 9, 3]} width={8} height={4.5} axis={{ numbers: true }} xLabel="x" yLabel="y" > <FunctionGraph function={(x) => x * x} /> </Axes> <DashedLine from={toScene(2, 0)} to={toScene(2, 4)} /> <LabeledDot center={toScene(2, 4)} minRadius={0.22} text="P" /> </Stage> );}Vector with components
A Vector grows out of the origin of a NumberPlane, then dashed lines drop to the axes to show its x and y components.
10 collapsed lines
import { derive, draw, track } from "@sophistry/core";import { DashedLine, NumberPlane, Stage, Text, usePlayer, Vector,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
export default function VectorArrow() { const { play } = usePlayer(); const arrow = track(0); const parts = track(0);
onSettled(() => { void (async () => { await play(draw(arrow, { duration: 1.2 })); await play(draw(parts, { duration: 0.8 })); })(); });
return ( <Stage units={12}> <NumberPlane xRange={[-4, 4]} yRange={[-3, 3]} width={8} height={6} /> <Vector to={{ x: 3, y: 2 }} strokeWidth={0.08} progress={arrow} /> {/* Dropped from the tip to each axis. */} <DashedLine from={{ x: 3, y: 2 }} to={{ x: 3, y: 0 }} progress={parts} /> <DashedLine from={{ x: 3, y: 2 }} to={{ x: 0, y: 2 }} progress={parts} /> {/* Each beside its own dashed line, clear of the axes' numbers and the shaft. */} <Text text="x = 3" x={3.65} y={1} opacity={parts} /> <Text text="y = 2" x={1.5} y={2.35} opacity={parts} /> {/* Arrives with the tip it names. */} <Text text="v = (3, 2)" x={3.95} y={2.45} opacity={derive(arrow, (drawn) => Math.max(0, (drawn - 0.7) / 0.3))} /> </Stage> );}Dimension annotation
A double-headed arrow and a live readout measure the width of a rectangle as it stretches and shrinks.
3 collapsed lines
import { derive, hold, sequence, track, valueTo } from "@sophistry/core";import { DoubleArrow, Rect, Stage, Text, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
export default function RectDimensions() { const { play, signal } = usePlayer(); const width = track(2);
onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( valueTo(width, 6, { duration: 1.5 }), hold(0.8), valueTo(width, 2, { duration: 1.5 }), hold(0.8), ), ); } })(); });
return ( <Stage units={10}> <Rect width={width} height={2} /> <DoubleArrow from={derive(width, (w) => ({ x: -w / 2, y: -1.5 }))} to={derive(width, (w) => ({ x: w / 2, y: -1.5 }))} /> <Text text={derive(width, (w) => `width = ${w.toFixed(1)}`)} y={-2.1} /> </Stage> );}Gradients and strokes
A lit sphere, a sheen that sweeps across a card, a dashed line and a stroke whose color follows the curve.
19 collapsed lines
import { colorRamp, derive, radialGradient, sheen, track, valueTo,} from "@sophistry/core";import { Circle, DashedLine, Path, Rect, Stage, Text, usePlayer, useScene,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
const wave = Array.from({ length: 60 }, (_, i) => ({ x: -1.6 + (i / 59) * 3.2, y: -0.9 + 0.5 * Math.sin((i / 59) * Math.PI * 3),}));
function Swatches() { const { play, signal } = usePlayer(); const series = derive(useScene().theme, (theme) => theme.palette.series); const at = track(0);
onSettled(() => { void (async () => { while (!signal.aborted) { at.set(0); await play(valueTo(at, 1, { duration: 2.5, easing: "linear" })); } })(); });
return ( <> <Circle center={{ x: -3.6, y: 0.6 }} radius={1.3} strokeWidth={0} fill={derive(series, (s) => radialGradient(["#ffffff", s[0], "#14213d"], { from: { x: 0.35, y: 0.7 }, }), )} /> <Text text="radialGradient" x={-3.6} y={-1.3} fontSize={0.3} />
<Rect center={{ x: 0, y: 0.6 }} width={3} height={2} cornerRadius={0.25} // From fully off one side of the card to fully off the other. fill={derive([series, at], (s, at) => sheen(s[1], { at: at * 1.7 - 0.35 }), )} stroke={derive(series, (s) => s[1])} /> <Text text="sheen, animated by at" y={-1.3} fontSize={0.3} />
<Path points={wave.map((p) => ({ x: p.x + 3.6, y: p.y + 1.5 }))} strokeWidth={0.14} strokeAlong={derive(series, (s) => { const heat = colorRamp([s[2], s[3], s[4]], { colorSpace: "oklch" }); return Array.from({ length: 24 }, (_, i) => heat(i / 23)); })} /> <DashedLine from={{ x: 2, y: -0.2 }} to={{ x: 5.2, y: -0.2 }} dashLength={0.18} strokeWidth={0.06} stroke={derive(series, (s) => s[3])} /> <Text text="strokeAlong + DashedLine" x={3.6} y={-1.3} fontSize={0.3} /> </> );}
export default function GradientsAndStrokes() { return ( <Stage units={12}> <Swatches /> </Stage> );}Theme colors
Every default color comes from the active theme; these swatches read its palette tokens and follow the site's light and dark mode.
3 collapsed lines
import { derive } from "@sophistry/core";import { Circle, Stage, Text, useScene } from "@sophistry/solidjs";import { For } from "solid-js";
const TOKENS = [ "accent", "highlight", "positive", "negative", "warning", "info",] as const;
function Swatches() { const theme = useScene().theme;
return ( <For each={TOKENS}> {(token, i) => { const color = derive(theme, (t) => t.palette[token]); return ( <> <Circle center={{ x: (i() - 2.5) * 1.9, y: 0 }} radius={0.7} stroke={color} fill={color} fillOpacity={0.4} /> <Text text={token} x={(i() - 2.5) * 1.9} y={-1.4} fontSize={0.3} /> </> ); }} </For> );}
export default function ThemeColors() { return ( <Stage units={12}> <Swatches /> </Stage> );}Palette switcher
Tap a swatch to hand the whole scene a different palette. Shapes, labels and the ground all restyle because they only read theme tokens.
4 collapsed lines
import type { PaletteSpec } from "@sophistry/core";import { definePalette, derive, resolvePalette } from "@sophistry/core";import { Circle, Rect, Stage, Text, useScene } from "@sophistry/solidjs";import { createSignal, For } from "solid-js";
const ocean = definePalette({ name: "ocean", dark: { background: "#07182b", foreground: "#e3f2ff", accent: "#38bdf8", series: ["#38bdf8", "#34d399", "#fbbf24", "#f472b6"], }, light: { background: "#f3f9ff", foreground: "#0b2a47", accent: "#0369a1", series: ["#0369a1", "#047857", "#b45309", "#be185d"], },});const ember = definePalette({ name: "ember", dark: { background: "#1c0d08", foreground: "#fde7d9", accent: "#fb923c", series: ["#fb923c", "#f87171", "#facc15", "#a78bfa"], }, light: { background: "#fff7f1", foreground: "#3b1405", accent: "#c2410c", series: ["#c2410c", "#b91c1c", "#a16207", "#6d28d9"], },});
const CHOICES: { name: string; palette: PaletteSpec }[] = [ { name: "catppuccin", palette: "catppuccin" }, { name: "ocean", palette: ocean }, { name: "ember", palette: ember },];
function Scene(props: { selected: () => number; select: (i: number) => void }) { const series = derive(useScene().theme, (theme) => theme.palette.series); return ( <> <For each={[0, 1, 2, 3]}> {(i) => { const color = derive(series, (s) => s[i % s.length]); return ( <Rect center={{ x: (i - 1.5) * 1.7, y: 0.9 }} width={1.3} height={(i + 1) * 0.45} stroke={color} fill={color} fillOpacity={0.4} /> ); }} </For> <For each={CHOICES}> {(choice, i) => ( <> <Circle center={{ x: (i() - 1) * 2.6, y: -1.6 }} radius={0.45} fill={resolvePalette(choice.palette).dark.accent} strokeWidth={props.selected() === i() ? 0.1 : 0.03} label={`${choice.name} palette`} cursor="pointer" onTap={() => props.select(i())} /> <Text text={choice.name} x={(i() - 1) * 2.6} y={-2.5} fontSize={0.28} /> </> )} </For> </> );}
export default function PaletteSwitcher() { // User input, so a Solid signal: the stage re-themes when it changes. const [selected, setSelected] = createSignal(0); return ( <Stage units={10} palette={CHOICES[selected()].palette}> <Scene selected={selected} select={setSelected} /> </Stage> );}RGB versus OKLCH blends
The same blue-to-yellow blend in two color spaces. RGB sags through a muddy gray in the middle; OKLCH keeps its lightness and sweeps the hue.
3 collapsed lines
import { derive, mixColor, toCss } from "@sophistry/core";import { Rect, Stage, Text, useScene } from "@sophistry/solidjs";import { For } from "solid-js";
const FROM = "#2563eb";const TO = "#facc15";const STEPS = 15;
function Strip(props: { y: number; colorSpace: "rgb" | "oklch"; name: string;}) { const muted = derive(useScene().theme, (theme) => theme.palette.muted); return ( <> <For each={Array.from({ length: STEPS }, (_, i) => i)}> {(i) => ( <Rect center={{ x: (i - (STEPS - 1) / 2) * 0.62, y: props.y }} width={0.62} height={1.1} strokeWidth={0} fill={toCss( mixColor(FROM, TO, i / (STEPS - 1), { colorSpace: props.colorSpace, }), )} /> )} </For> <Text text={props.name} y={props.y - 0.95} fontSize={0.3} color={muted} /> </> );}
export default function OklchBlend() { return ( <Stage units={11}> <Strip y={1.1} colorSpace="rgb" name={'mixColor(a, b, t, { colorSpace: "rgb" })'} /> <Strip y={-1.5} colorSpace="oklch" name={'mixColor(a, b, t, { colorSpace: "oklch" })'} /> </Stage> );}Boxes and layout
A card laid out with flexbox in design pixels: a heading, wrapped rich text, a row of tags and a circle in scene units, written on in order.
3 collapsed lines
import { BLUE, lagged, track, valueTo, YELLOW } from "@sophistry/core";import { Box, Circle, Stage, Text, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
export default function BoxLayout() { const { play } = usePlayer(); const heading = track(0); const body = track(0); const shape = track(0);
onSettled(() => { void play( lagged( [heading, body, shape].map((t) => valueTo(t, 1, { duration: 1.2, easing: "linear" }), ), { lagRatio: 0.7 }, ), ); });
const tag = (label: string) => ( <Box style={{ paddingTop: 8, paddingBottom: 8, paddingLeft: 20, paddingRight: 20, borderRadius: 999, background: "#2b3a52", fontSize: 28, }} > <Text text={label} progress={body} /> </Box> );
return ( <Stage> <Box style={{ width: 1400, flexDirection: "row", gap: 56, padding: 64, background: "#16202e", borderWidth: 3, borderColor: "#3d5170", borderRadius: 40, color: "#e6edf5", fontSize: 36, alignItems: "center", }} > <Box style={{ flex: 1, flexDirection: "column", gap: 28 }}> <Text text="Fourier series" fontSize={84} fontWeight={700} progress={heading} /> <Text text={[ "Any reasonable ", { text: "periodic", italic: true, color: YELLOW }, " function is a sum of sines and cosines, each a whole multiple of one ", { text: "fundamental frequency", fontWeight: 700, color: BLUE }, ".", ]} progress={body} /> <Box style={{ flexDirection: "row", gap: 16 }}> {tag("analysis")} {tag("signals")} {tag("heat equation")} </Box> </Box> <Circle radius={1.6} stroke={BLUE} strokeWidth={0.06} progress={shape} /> </Box> </Stage> );}Braces
Braces measure a rectangle's sides and a triangle's hypotenuse, each with a label at its tip, drawn in one after another.
4 collapsed lines
import type { SceneNode } from "@sophistry/core";import { DOWN, draw, lagged, RIGHT, track } from "@sophistry/core";import { Brace, Polygon, Rect, Stage, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
const A = { x: 1.5, y: -1.5 };const B = { x: 5, y: -1.5 };const C = { x: 5, y: 1.5 };
export default function BraceAnnotations() { const { play } = usePlayer(); const braces = [track(0), track(0), track(0)]; // The node is the handle: the rectangle exists before the braces read its bounds. let box!: SceneNode;
onSettled(() => { void play( lagged( braces.map((b) => draw(b)), { lagRatio: 0.6 }, ), ); });
return ( <Stage units={12}> <Rect ref={(node) => (box = node)} center={{ x: -2.5, y: 0 }} width={4} height={2} /> <Brace target={box.bounds()} direction={DOWN} label="width" progress={braces[0]} /> <Brace target={box.bounds()} direction={RIGHT} label="h" progress={braces[1]} /> <Polygon points={[A, B, C]} /> {/* C to A: the tip points to the right of travel, away from the triangle. */} <Brace from={C} to={A} gap={0.15} label="c" progress={braces[2]} /> </Stage> );}Clipping a group
A <Group clip> paints its children only inside a region. Here the clip's right edge follows a track, wiping a coloured copy over a grey one.
3 collapsed lines
import { derive, sequence, track, valueTo } from "@sophistry/core";import { Circle, Group, Line, Stage, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
const dots = Array.from({ length: 35 }, (_, i) => ({ x: (i % 7) - 3, y: Math.floor(i / 7) - 2,}));
export default function ClipWipe() { const { play, signal } = usePlayer(); const edge = track(-4); onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( valueTo(edge, 4, { duration: 2 }), valueTo(edge, -4, { duration: 2 }), ), ); } })(); });
const picture = (color: string) => dots.map((d) => ( <Circle center={d} radius={0.35} fill={color} stroke="none" /> ));
return ( <Stage units={10}> {picture("#8a8a8a")} <Group clip={derive(edge, (x) => ({ minX: -4, minY: -3, maxX: x, maxY: 3 }))} > {picture("#58c4dd")} </Group> <Line from={derive(edge, (x) => ({ x, y: -3 }))} to={derive(edge, (x) => ({ x, y: 3 }))} /> </Stage> );}Grid layout
A box with display: grid: a title spanning every column, three equal columns of cards, and a footer row, with tracks in design pixels and fr.
2 collapsed lines
import { BLUE, GREEN, RED, YELLOW } from "@sophistry/core";import { Box, Circle, Square, Stage, Star, Text } from "@sophistry/solidjs";
const card = { padding: 28, gap: 16, flexDirection: "column", alignItems: "center", background: "#22304a", borderRadius: 24,} as const;
export default function GridLayout() { return ( <Stage> <Box style={{ display: "grid", width: 1300, gridTemplateColumns: [{ repeat: 3, tracks: [{ fr: 1 }] }], gap: 28, padding: 48, background: "#16202e", borderRadius: 36, color: "#e6edf5", fontSize: 36, }} > <Box style={{ gridColumn: { span: 3 } }}> <Text text="Three shapes" fontSize={64} fontWeight={700} /> </Box> <Box style={card}> <Circle radius={0.7} stroke={BLUE} strokeWidth={0.05} /> <Text text="circle" /> </Box> <Box style={card}> <Square size={1.3} stroke={GREEN} strokeWidth={0.05} /> <Text text="square" /> </Box> <Box style={card}> <Star outerRadius={0.8} stroke={RED} strokeWidth={0.05} /> <Text text="star" /> </Box> <Box style={{ gridColumn: { start: 2, span: 2 }, justifyContent: "flex-end", color: YELLOW, fontSize: 28, }} > <Text text="the footer spans the last two columns" /> </Box> </Box> </Stage> );}Formulas inside sentences
Any scene node can sit in a line of text like a wide glyph: a typeset formula mid-sentence and a coloured dot as a legend key, wrapping with the words around them.
3 collapsed lines
import { BLUE, circle, YELLOW } from "@sophistry/core";import { Box, Stage, Text } from "@sophistry/solidjs";import { mathTex } from "@sophistry/text";
const INK = "#e6edf5";
export default function InlineFormula() { return ( <Stage> <Box style={{ width: 1100, padding: 56, gap: 32, flexDirection: "column", background: "#16202e", borderRadius: 32, color: INK, fontSize: 44, }} > <Text text={[ "The roots of ", { inline: mathTex.create({ tex: "ax^2 + bx + c", fontSize: 0.42, fill: INK, }), }, " are ", { inline: mathTex.create({ tex: "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}", fontSize: 0.42, fill: INK, }), }, ", real exactly when the discriminant is not negative.", ]} /> <Text fontSize={34} text={[ { inline: circle.create({ radius: 0.1, fill: BLUE, stroke: "none", }), }, " measured ", { inline: circle.create({ radius: 0.1, fill: YELLOW, stroke: "none", }), }, " predicted", ]} /> </Box> </Stage> );}Layout transitions
layoutTo changes boxes' styles and children and moves everything to its new place: tiles reorder, then the row turns into a column, each tile gliding there.
3 collapsed lines
import { type BoxNode, hold, layoutTo, sequence } from "@sophistry/core";import { Box, Stage, Text, usePlayer } from "@sophistry/solidjs";import { onSettled } from "solid-js";
const tiles = [ { label: "sin", color: "#58c4dd" }, { label: "cos", color: "#83c167" }, { label: "tan", color: "#fc6255" }, { label: "exp", color: "#f0ac5f" },];
const row = { flexDirection: "row", gap: 32, padding: 40, background: "#16202e", borderRadius: 32, color: "#0b1018", fontSize: 56, fontWeight: 700,} as const;
const column = { ...row, flexDirection: "column", gap: 20 } as const;
export default function LayoutTransition() { const { play, signal } = usePlayer(); let container: BoxNode | undefined; const nodes: BoxNode[] = [];
onSettled(() => { void (async () => { while (!signal.aborted && container) { const [a, b, c, d] = nodes as [BoxNode, BoxNode, BoxNode, BoxNode]; await play( sequence( hold(0.6), layoutTo(container, { children: [d, b, a, c] }, { duration: 1 }), hold(0.6), layoutTo(container, { style: column }, { duration: 1 }), hold(0.6), layoutTo( container, { style: row, children: [a, b, c, d] }, { duration: 1 }, ), ), ); } })(); });
return ( <Stage> <Box style={row} ref={(node) => (container = node)}> {tiles.map((tile, index) => ( <Box ref={(node) => (nodes[index] = node)} style={{ width: 200, paddingTop: 24, paddingBottom: 24, borderRadius: 20, background: tile.color, justifyContent: "center", }} > <Text text={tile.label} /> </Box> ))} </Box> </Stage> );}Scene units and the frame
A unit grid with y pointing up, the origin at the center, and the visible frame read back from useScene().frame: units={8} at 16:9 spans x from -4 to 4 and y from -2.25 to 2.25.
4 collapsed lines
import type { ColorInput, ThemePalette } from "@sophistry/core";import { derive } from "@sophistry/core";import { Dot, Line, Stage, Text, useScene } from "@sophistry/solidjs";import { For } from "solid-js";
const XS = [-4, -3, -2, -1, 0, 1, 2, 3, 4];const YS = [-2, -1, 0, 1, 2];
function Grid() { const scene = useScene(); // A colour that follows the theme (and the site's light and dark mode). const palette = (pick: (palette: ThemePalette) => ColorInput) => derive(scene.theme, (theme) => pick(theme.palette)); const frame = scene.frame;
return ( <> <For each={XS}> {(x) => ( <Line from={derive(frame, (f) => ({ x, y: f.minY }))} to={derive(frame, (f) => ({ x, y: f.maxY }))} stroke={palette((p) => (x === 0 ? p.muted : p.grid))} strokeWidth={x === 0 ? 0.03 : 0.015} /> )} </For> <For each={YS}> {(y) => ( <Line from={derive(frame, (f) => ({ x: f.minX, y }))} to={derive(frame, (f) => ({ x: f.maxX, y }))} stroke={palette((p) => (y === 0 ? p.muted : p.grid))} strokeWidth={y === 0 ? 0.03 : 0.015} /> )} </For> <Dot center={{ x: 1, y: 1.5 }} color={palette((p) => p.series[0])} radius={0.08} /> <Text text="(1, 1.5)" x={1.15} y={1.5} align="left" fontSize={0.2} color={palette((p) => p.series[0])} /> <Text text="origin" x={0.12} y={-0.15} align="left" fontSize={0.2} color={palette((p) => p.muted)} /> <Text text={derive( frame, (f) => `frame: x ${f.minX} to ${f.maxX}, y ${f.minY} to ${f.maxY}`, )} y={derive(frame, (f) => f.minY + 0.3)} fontSize={0.2} color={palette((p) => p.muted)} // Lifted off the grid and axis lines that run under it. halo /> </> );}
export default function SceneUnitsFrame() { return ( <Stage units={8}> <Grid /> </Stage> );}Text blocks, lists and titles
A title with its rule, rich text wrapped to a measure and a bulleted list, each written in reading order or an item at a time.
9 collapsed lines
import { BLUE, lagged, track, valueTo } from "@sophistry/core";import { BulletedList, Stage, Text, Title, usePlayer,} from "@sophistry/solidjs";import { onSettled } from "solid-js";
export default function TextBlocks() { const { play } = usePlayer(); const title = track(0); const paragraph = track(0); const list = track(0);
onSettled(() => { void play( lagged( [title, paragraph, list].map((t) => valueTo(t, 1, { duration: 1.5, easing: "linear" }), ), { lagRatio: 0.8 }, ), ); });
return ( <Stage units={14}> <Title text="Continuity" progress={title} /> <Text x={-3} y={0.6} width={6} fontSize={0.36} textAlign="left" text={[ "A function is ", { text: "continuous", fontWeight: 700, color: BLUE }, " at a point when small changes in its input give small changes in its output. Nothing ", { text: "jumps", italic: true }, ", and nothing is ", { text: "missing", underline: true }, ".", ]} progress={paragraph} /> <BulletedList x={3.8} y={0.6} fontSize={0.36} items={["No jumps", "No holes", "No vertical asymptotes"]} progress={list} /> </Stage> );}