Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: crumple toss
kapishdimaee5d07ac0ae0
diff --git a/components/docs/examples/crumple-toss-example.tsx b/components/docs/examples/crumple-toss-example.tsxnew file mode 100644index 00000000..2c8fcd17--- /dev/null+++ b/components/docs/examples/crumple-toss-example.tsx@@ -0,0 +1,207 @@+"use client";++import { AbsoluteFill, useCurrentFrame } from "remotion";+import {+ CrumpleToss,+ crumpleTossLanding,+ crumpleTossPose,+} from "@/registry/remocn/crumple-toss";++const FONT_FAMILY =+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif";++const INK = "#26242c";+const PENCIL = "rgba(38,36,44,0.55)";++const CARD_WIDTH = 380;+const CARD_HEIGHT = 220;++const BIN_WIDTH = 150;+const BIN_HEIGHT = 170;+const RIM_HEIGHT = 30;+const BIN_BODY = "#ded8ca";+const BIN_INSIDE = "#bdb6a5";+const BIN_RIB = "rgba(38,36,44,0.09)";++const Card = ({ title, body }: { title: string; body: string }) => (+ <div+ style={{+ width: CARD_WIDTH,+ height: CARD_HEIGHT,+ padding: 28,+ boxSizing: "border-box",+ display: "flex",+ flexDirection: "column",+ justifyContent: "center",+ gap: 10,+ background: "#fdfcf8",+ border: "1px solid rgba(38,36,44,0.12)",+ boxShadow: "0 8px 20px rgba(38,36,44,0.12)",+ fontFamily: FONT_FAMILY,+ }}+ >+ <div style={{ fontSize: 15, color: PENCIL }}>{title}</div>+ <div style={{ fontSize: 30, fontWeight: 600, color: INK, lineHeight: 1.2 }}>+ {body}+ </div>+ </div>+);++export function CrumpleTossExampleScene({+ at = 6,+ segments = 9,+ layers = 2,+ randomness = 0.6,+ crumpleSteps = 4,+ tossSteps = 5,+ direction = -35,+ distance = 440,+ spin = 220,+ crushTo = 0.34,+ seed = "toss",+ step = 3,+}: {+ at?: number;+ segments?: number;+ layers?: number;+ randomness?: number;+ crumpleSteps?: number;+ tossSteps?: number;+ direction?: number;+ distance?: number;+ spin?: number;+ crushTo?: number;+ seed?: string;+ step?: number;+}) {+ const frame = useCurrentFrame();+ const pose = crumpleTossPose({+ frame,+ at,+ crumpleSteps,+ tossSteps,+ step,+ });+ const binIsOut = pose.crush >= 1;++ const landing = crumpleTossLanding({ direction, distance });+ const binLeft = CARD_WIDTH / 2 + landing.x - BIN_WIDTH / 2;+ const binTop = CARD_HEIGHT / 2 + landing.y;++ return (+ <AbsoluteFill style={{ alignItems: "center", justifyContent: "center" }}>+ <div+ style={{+ position: "relative",+ width: CARD_WIDTH,+ height: CARD_HEIGHT,+ }}+ >+ {binIsOut ? (+ <div+ style={{+ position: "absolute",+ left: binLeft,+ top: binTop - RIM_HEIGHT / 2,+ width: BIN_WIDTH,+ height: RIM_HEIGHT,+ borderRadius: "50%",+ background: BIN_INSIDE,+ }}+ />+ ) : null}++ <div style={{ position: "absolute", inset: 0 }}>+ <CrumpleToss+ width={CARD_WIDTH}+ height={CARD_HEIGHT}+ segments={segments}+ layers={layers}+ randomness={randomness}+ at={at}+ crumpleSteps={crumpleSteps}+ tossSteps={tossSteps}+ direction={direction}+ distance={distance}+ spin={spin}+ crushTo={crushTo}+ seed={seed}+ step={step}+ >+ <Card+ title="How it used to work"+ body="Six steps and a wiki page"+ />+ </CrumpleToss>+ </div>++ {binIsOut ? (+ <div+ style={{+ position: "absolute",+ left: binLeft,+ top: binTop,+ width: BIN_WIDTH,+ height: BIN_HEIGHT,+ clipPath: "polygon(0% 0%, 100% 0%, 84% 100%, 16% 100%)",+ background: BIN_BODY,+ }}+ >+ {[0.3, 0.5, 0.7].map((rib) => (+ <div+ key={rib}+ style={{+ position: "absolute",+ left: `${rib * 100}%`,+ top: 0,+ bottom: 0,+ width: 2,+ background: BIN_RIB,+ }}+ />+ ))}+ </div>+ ) : null}+ </div>+ </AbsoluteFill>+ );+}++export const crumpleTossExampleCode = (+ values: Record<string, unknown>,+): string => {+ const at = (values.at as number) ?? 6;+ const segments = (values.segments as number) ?? 9;+ const layers = (values.layers as number) ?? 2;+ const randomness = (values.randomness as number) ?? 0.6;+ const crumpleSteps = (values.crumpleSteps as number) ?? 4;+ const tossSteps = (values.tossSteps as number) ?? 5;+ const direction = (values.direction as number) ?? -35;+ const distance = (values.distance as number) ?? 900;+ const spin = (values.spin as number) ?? 220;+ const crushTo = (values.crushTo as number) ?? 0.34;+ const seed = (values.seed as string) ?? "toss";+ const step = (values.step as number) ?? 3;+ return `import { CrumpleToss } from "@/components/remocn/crumple-toss";++export const MyScene = () => (+ <CrumpleToss+ width={${CARD_WIDTH}}+ height={${CARD_HEIGHT}}+ segments={${segments}}+ layers={${layers}}+ randomness={${randomness}}+ at={${at}}+ crumpleSteps={${crumpleSteps}}+ tossSteps={${tossSteps}}+ direction={${direction}}+ distance={${distance}}+ spin={${spin}}+ crushTo={${crushTo}}+ seed="${seed}"+ step={${step}}+ >+ <YourCard />+ </CrumpleToss>+);`;+};diff --git a/components/docs/examples/index.tsx b/components/docs/examples/index.tsxindex a6697fcd..a78751c9 100644--- a/components/docs/examples/index.tsx+++ b/components/docs/examples/index.tsx@@ -21,6 +21,10 @@ import {ContextMenuExampleScene,contextMenuExampleCode,} from "./context-menu-example";+import {+ CrumpleTossExampleScene,+ crumpleTossExampleCode,+} from "./crumple-toss-example";import { CursorExampleScene, cursorExampleCode } from "./cursor-example";import { DialogExampleScene, dialogExampleCode } from "./dialog-example";import { DrawerExampleScene, drawerExampleCode } from "./drawer-example";@@ -92,6 +96,15 @@ export interface ExampleEntry {}export const examples: Record<string, ExampleEntry> = {+ "crumple-toss-example": {+ Component: CrumpleTossExampleScene,+ code: crumpleTossExampleCode,+ durationInFrames: 90,+ fps: FPS,+ width: W,+ height: H,+ previewBackdrop: { type: "color", value: "#f1eee7" },+ },"button-example": {Component: ButtonExampleScene,code: buttonExampleCode,diff --git a/content/docs/components.mdx b/content/docs/components.mdxindex 9a3e0b75..4e98bfe7 100644--- a/content/docs/components.mdx+++ b/content/docs/components.mdx@@ -495,6 +495,12 @@ Physical overlays and hand-made motion.status: "stable",href: "/docs/effects/scribble-circle",},+ {+ name: "CrumpleToss",+ description: "Crushes an element into a ball of paper and throws it out of frame",+ status: "stable",+ href: "/docs/effects/crumple-toss",+ },{name: "Confetti",description: "A one-shot burst of paper confetti for milestone and celebration beats",diff --git a/content/docs/effects/crumple-toss.mdx b/content/docs/effects/crumple-toss.mdxnew file mode 100644index 00000000..4aee4474--- /dev/null+++ b/content/docs/effects/crumple-toss.mdx@@ -0,0 +1,232 @@+---+title: Crumple Toss+description: Crushes an element into a ball of paper and throws it out of frame+---++<ComponentPreview name="crumple-toss" />++## Installation++<InstallBlock name="crumple-toss" />++## Usage++Everything else in the kit **arrives**. This is the piece that takes something+off the desk: it crushes one element into a ball and throws it away while the+scene around it keeps running.++That unlocks the beat product videos lean on — *this is how it used to work* →+crumple → *here is the new way*. Stack the replacement behind it and it is+revealed as the ball leaves.++```tsx+// src/Root.tsx+import { AbsoluteFill, Composition } from "remotion";+import { CrumpleToss } from "@/components/remocn/crumple-toss";++const BeforeAfterScene = () => (+ <AbsoluteFill+ style={{+ background: "#f1eee7",+ alignItems: "center",+ justifyContent: "center",+ }}+ >+ <div style={{ position: "relative", width: 380, height: 220 }}>+ <div style={{ position: "absolute", inset: 0 }}>+ <NewWayCard />+ </div>+ <div style={{ position: "absolute", inset: 0 }}>+ <CrumpleToss width={380} height={220} at={6}>+ <OldWayCard />+ </CrumpleToss>+ </div>+ </div>+ </AbsoluteFill>+);++export const RemotionRoot = () => (+ <Composition+ id="CrumpleToss"+ component={BeforeAfterScene}+ durationInFrames={90}+ fps={30}+ width={1280}+ height={720}+ />+);+```++The children are never modified — each wedge renders its own copy and clips to+its slice — so a `polaroid`, a chart, or a whole composed card can be thrown+as-is.++`width` and `height` are required: the fold geometry is computed in pixels, and+measuring the child would not survive Remotion's server-side render. It is the+same call `scribble-circle` makes.++### It is an exit, not a transition++`crumple-toss` removes **one element** while everything else carries on. It is+not a `TransitionPresentation` and does not belong in a `<TransitionSeries>`.+For a scene-level paper exit, `page-turn` replaces the whole frame.++### The card folds into the ball — there is no swap++This is the part worth understanding, because the naive version is visibly+wrong. The component does **not** hide your card and reveal a ball on top; you+would see the cut. Instead the card is sliced into wedges radiating from its+centre, and each wedge carries its own piece of the content while it folds+inward, rotates, and shrinks. The wad **is** the card, folded.++At rest the wedges tile the card exactly — their areas sum to the whole box —+so before `at` there is nothing to see. `segments` sets how many pieces the+paper tears into; more pieces read as thinner paper.++Each wedge is then cut again, radially, into `layers` panels: a core panel near+the middle and one or more rim panels out toward the edge. This is what stops+the fold reading as a card sliced into pie slices. A single layer gives long+straight seams running from the centre to the rim; splitting them lets the+inner and outer halves of one wedge fold by different amounts, so the seam+zigzags the way a crease does. The wedge still curls **one way** — the tilt+grows toward the rim rather than flipping sign halfway — because paper bends,+it does not hinge in the middle of a panel.++Layers cost render time: the child is drawn once per panel, so `segments × layers`+copies. The default 9 × 2 is cheap; 14 × 3 is 42 copies of whatever you pass in.++`randomness` is how uneven the fold is. At `0` every wedge folds identically —+even angles, no tilt, all panels landing the same distance in — which reads as+neat origami and, notably, ignores `seed` entirely because there is nothing+left to randomise. Turn it up and the wedges tear at uneven angles, tilt+further, and land at different depths. `1` is a proper mess.++Each panel is shaded as it folds, so the finished wad has lit faces and+shadowed creases rather than reading as a flat blob. The shading is not one+flat wash per panel — that just tints triangles. Every facet gets a light side+and a dark side with a fold between them, and the gradient counter-rotates+against the panel's own tilt so the light stays fixed while the paper turns+under it. Panels nearer the core are shaded darker, because the inside of a+wad is occluded.++All of it only fades in with the crush, which is why the card looks untouched+until it starts.++### Aiming the throw++`direction` is measured in screen space: `0` throws right, **negative angles+throw upward**, and anything past `±90` throws leftward. The default `-35`+sends the ball up and away.++`distance` is the **scale of the arc, not the pixels travelled** — gravity is+added on top of the launch, so at the defaults a `distance` of 900 puts the+ball 737px right and 294px down, a 794px displacement.++The opacity drops once, on the final flight pose, and then the element is gone.+Everything in this kit is constant within a pose, so there is no sub-pose time+to fade across; one stepped drop reads as the ball leaving, where a gradient+would read as a dissolve.++### It returns null when it is done++After `at + (crumpleSteps + tossSteps) * step` the component renders nothing.+In absolute positioning — the intended use — that is invisible. In normal flow+the element's box collapses on that frame, so wrap it in an `<AbsoluteFill>` or+a sized container if the layout has to hold.++## Props++<PropsTable+ rows={[+ {+ name: "children",+ type: "React.ReactNode",+ required: true,+ description: "What gets thrown away; it is never modified",+ },+ {+ name: "width",+ type: "number",+ required: true,+ description: "Width of what is being thrown; the fold geometry derives from it",+ },+ {+ name: "height",+ type: "number",+ required: true,+ description: "Height of what is being thrown",+ },+ {+ name: "at",+ type: "number",+ required: true,+ description: "Frame the crumple starts; nothing moves before it",+ },+ {+ name: "segments",+ type: "number",+ default: "9",+ description: "Wedges the paper tears into; more pieces read as thinner paper",+ },+ {+ name: "layers",+ type: "number",+ default: "2",+ description: "Radial cuts per wedge; 1 gives straight seams, more breaks the fold up",+ },+ {+ name: "randomness",+ type: "number",+ default: "0.6",+ description: "How uneven the fold is; 0 folds every wedge identically and ignores seed",+ },+ {+ name: "crumpleSteps",+ type: "number",+ default: "4",+ description: "Poses spent crushing",+ },+ {+ name: "tossSteps",+ type: "number",+ default: "5",+ description: "Poses spent in flight",+ },+ {+ name: "direction",+ type: "number",+ default: "-35",+ description: "Throw angle in screen space; negative throws upward, past ±90 throws left",+ },+ {+ name: "distance",+ type: "number",+ default: "900",+ description: "Scale of the throw arc, not the pixels travelled",+ },+ {+ name: "spin",+ type: "number",+ default: "220",+ description: "Degrees of tumble across the flight",+ },+ {+ name: "crushTo",+ type: "number",+ default: "0.34",+ description: "Size of the finished wad, as a fraction of the shorter side",+ },+ {+ name: "seed",+ type: "string",+ default: "\"toss\"",+ description: "Seed for the wedge angles, the fold tilts, and where each panel lands",+ },+ {+ name: "step",+ type: "number",+ default: "3",+ description: "Frames per stop-motion pose",+ },+ ]}+/>diff --git a/content/docs/effects/meta.json b/content/docs/effects/meta.jsonindex 39cfc9c6..37300bc4 100644--- a/content/docs/effects/meta.json+++ b/content/docs/effects/meta.json@@ -1,5 +1,12 @@{"title": "Effects","collapsible": false,- "pages": ["index", "confetti", "paper-wobble", "ink-arrow", "scribble-circle"]+ "pages": [+ "index",+ "confetti",+ "paper-wobble",+ "ink-arrow",+ "scribble-circle",+ "crumple-toss"+ ]}diff --git a/registry-artifacts/crumple-toss.json b/registry-artifacts/crumple-toss.jsonnew file mode 100644index 00000000..80c1075a--- /dev/null+++ b/registry-artifacts/crumple-toss.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "crumple-toss",+ "title": "Crumple Toss",+ "description": "Crushes an element into a ball of paper and throws it out of frame on an arc, leaving the scene around it running.",+ "dependencies": ["remotion"],+ "registryDependencies": ["@remocn/stop-motion"],+ "files": [+ {+ "path": "registry/remocn/crumple-toss/index.tsx",+ "content": "\"use client\";\n\nimport type React from \"react\";\nimport { useCurrentFrame } from \"remotion\";\nimport { DEFAULT_STEP, hashRange, qstep } from \"@/lib/remocn/stop-motion\";\n\nconst GRAVITY = 0.9;\nconst FLIGHT_SHRINK = 0.5;\nconst EXIT_OPACITY = 0.4;\n\nconst FOLD_TILT = 46;\nconst WAD_REACH = 0.27;\nconst WAD_SPREAD = 0.07;\nconst ANGLE_JITTER = 0.22;\nconst SCALE_SPREAD = 0.25;\nconst DEFAULT_RANDOMNESS = 0.6;\nconst DEFAULT_LAYERS = 2;\nconst LAYER_TILT_FLOOR = 0.45;\nconst FACET_SIZE = 0.5;\nconst FACET_CAP = 0.5;\n\nconst TONE_PATTERN = [0, 1, 3, 1, 0, 2, 1, 2, 0];\n\nconst TONES = [\n { lit: \"rgba(255,255,255,0.66)\", dark: \"rgba(255,255,255,0.18)\" },\n { lit: \"rgba(255,255,255,0.30)\", dark: \"rgba(38,36,44,0.10)\" },\n { lit: \"rgba(255,255,255,0.08)\", dark: \"rgba(38,36,44,0.20)\" },\n { lit: \"rgba(38,36,44,0.06)\", dark: \"rgba(38,36,44,0.30)\" },\n];\n\nconst LIGHT_ANGLE = -55;\nconst CREASE_BLEND = 9;\n\nexport type CrumplePhase = \"idle\" | \"crumple\" | \"toss\" | \"gone\";\n\nexport type CrumplePose = {\n phase: CrumplePhase;\n crush: number;\n scale: number;\n rotate: number;\n x: number;\n y: number;\n opacity: number;\n};\n\nexport type CrumpleSegment = {\n clip: [number, number][];\n origin: [number, number];\n dx: number;\n dy: number;\n scale: number;\n rotate: number;\n tone: number;\n crease: number;\n};\n\nexport type CrumpleTossTiming = {\n at: number;\n crumpleSteps?: number;\n tossSteps?: number;\n direction?: number;\n distance?: number;\n spin?: number;\n crushTo?: number;\n seed?: string;\n step?: number;\n};\n\nconst rayToEdge = (\n angle: number,\n halfWidth: number,\n halfHeight: number,\n): [number, number] => {\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n const t = Math.min(\n halfWidth / (Math.abs(cos) || 1e-9),\n halfHeight / (Math.abs(sin) || 1e-9),\n );\n return [cos * t, sin * t];\n};\n\nconst normalize = (angle: number) => {\n const turn = Math.PI * 2;\n return ((angle % turn) + turn) % turn;\n};\n\nconst shrinkToward = (\n [x, y]: [number, number],\n factor: number,\n): [number, number] => [x * factor, y * factor];\n\nconst averageOf = (points: [number, number][]): [number, number] => [\n points.reduce((sum, p) => sum + p[0], 0) / points.length,\n points.reduce((sum, p) => sum + p[1], 0) / points.length,\n];\n\nexport function crumpleSegments(args: {\n width: number;\n height: number;\n segments?: number;\n layers?: number;\n crushTo?: number;\n randomness?: number;\n seed?: string;\n}): CrumpleSegment[] {\n const count = Math.max(3, Math.round(args.segments ?? 9));\n const layers = Math.max(1, Math.round(args.layers ?? DEFAULT_LAYERS));\n const crushTo = args.crushTo ?? 0.34;\n const chaos = Math.min(1, Math.max(0, args.randomness ?? DEFAULT_RANDOMNESS));\n const seed = args.seed ?? \"toss\";\n const halfWidth = args.width / 2;\n const halfHeight = args.height / 2;\n const wad = Math.min(args.width, args.height) * crushTo;\n\n const angles = Array.from(\n { length: count },\n (_, i) =>\n (i / count) * Math.PI * 2 +\n hashRange(`${seed}:ang${i}`, -ANGLE_JITTER, ANGLE_JITTER) * chaos,\n );\n\n const corners: [number, number][] = [\n [halfWidth, halfHeight],\n [-halfWidth, halfHeight],\n [-halfWidth, -halfHeight],\n [halfWidth, -halfHeight],\n ];\n\n const toPercent = ([x, y]: [number, number]): [number, number] => [\n ((x + halfWidth) / args.width) * 100,\n ((y + halfHeight) / args.height) * 100,\n ];\n\n const panels: CrumpleSegment[] = [];\n\n angles.forEach((angle, i) => {\n const nextAngle =\n angles[(i + 1) % count] + (i === count - 1 ? Math.PI * 2 : 0);\n const from = rayToEdge(angle, halfWidth, halfHeight);\n const to = rayToEdge(nextAngle, halfWidth, halfHeight);\n\n const span = normalize(nextAngle - angle);\n const between = corners\n .map((corner): [[number, number], number] => [\n corner,\n normalize(Math.atan2(corner[1], corner[0]) - angle),\n ])\n .filter(([, spanned]) => spanned > 0 && spanned < span)\n .sort((a, b) => a[1] - b[1])\n .map(([corner]) => corner);\n\n const rim: [number, number][] = [from, ...between, to];\n\n for (let layer = 0; layer < layers; layer++) {\n const inner = layer / layers;\n const outer = (layer + 1) / layers;\n const depth = (layer + 1) / layers;\n const shape: [number, number][] =\n layer === 0\n ? [[0, 0], ...rim.map((point) => shrinkToward(point, outer))]\n : [\n ...rim.map((point) => shrinkToward(point, outer)),\n ...[...rim].reverse().map((point) => shrinkToward(point, inner)),\n ];\n\n const centroid = averageOf(shape);\n const extent =\n Math.max(\n ...shape.map((point) =>\n Math.hypot(point[0] - centroid[0], point[1] - centroid[1]),\n ),\n ) || 1;\n const key = `${seed}:${i}:${layer}`;\n\n const reach =\n wad *\n (WAD_REACH * depth +\n hashRange(`${key}:reach`, -WAD_SPREAD, WAD_SPREAD) * chaos * depth);\n const heading = Math.atan2(centroid[1], centroid[0]);\n\n panels.push({\n clip: shape.map(toPercent),\n origin: toPercent(centroid),\n dx: Math.cos(heading) * reach - centroid[0],\n dy: Math.sin(heading) * reach - centroid[1],\n scale:\n Math.min(FACET_CAP, (wad * FACET_SIZE) / extent) *\n (1 + hashRange(`${key}:size`, -SCALE_SPREAD, SCALE_SPREAD) * chaos),\n rotate:\n chaos === 0\n ? 0\n : hashRange(`${seed}:tilt${i}`, -FOLD_TILT, FOLD_TILT) *\n chaos *\n (LAYER_TILT_FLOOR + (1 - LAYER_TILT_FLOOR) * depth),\n tone: Math.min(\n TONES.length - 1,\n TONE_PATTERN[panels.length % TONE_PATTERN.length] +\n Math.ceil((1 - depth) * 2),\n ),\n crease: 0.5 + hashRange(`${key}:crease`, -0.2, 0.2) * chaos,\n });\n }\n });\n\n return panels;\n}\n\nexport function creaseShading(\n piece: Pick<CrumpleSegment, \"tone\" | \"rotate\" | \"crease\">,\n crush: number,\n): string {\n const tone = TONES[piece.tone];\n const fold = piece.crease * 100;\n const lit = Math.max(0, fold - CREASE_BLEND).toFixed(1);\n const dark = Math.min(100, fold + CREASE_BLEND).toFixed(1);\n const angle = (LIGHT_ANGLE - piece.rotate * crush).toFixed(1);\n return `linear-gradient(${angle}deg, ${tone.lit} 0%, ${tone.lit} ${lit}%, ${tone.dark} ${dark}%, ${tone.dark} 100%)`;\n}\n\nexport function crumpleTossLanding(options?: {\n direction?: number;\n distance?: number;\n}): { x: number; y: number } {\n const distance = options?.distance ?? 900;\n const radians = ((options?.direction ?? -35) * Math.PI) / 180;\n return {\n x: distance * Math.cos(radians),\n y: distance * Math.sin(radians) + GRAVITY * distance,\n };\n}\n\nexport function crumpleTossPose(\n args: CrumpleTossTiming & { frame: number },\n): CrumplePose {\n const crumpleSteps = args.crumpleSteps ?? 4;\n const tossSteps = args.tossSteps ?? 5;\n const direction = args.direction ?? -35;\n const distance = args.distance ?? 900;\n const spin = args.spin ?? 220;\n const step = args.step ?? DEFAULT_STEP;\n\n if (args.frame < args.at) {\n return {\n phase: \"idle\",\n crush: 0,\n scale: 1,\n rotate: 0,\n x: 0,\n y: 0,\n opacity: 1,\n };\n }\n\n const pose = qstep(args.frame - args.at, step);\n\n if (pose < crumpleSteps) {\n return {\n phase: \"crumple\",\n crush: (pose + 1) / crumpleSteps,\n scale: 1,\n rotate: 0,\n x: 0,\n y: 0,\n opacity: 1,\n };\n }\n\n if (pose < crumpleSteps + tossSteps) {\n const t = (pose - crumpleSteps + 1) / tossSteps;\n const radians = (direction * Math.PI) / 180;\n return {\n phase: \"toss\",\n crush: 1,\n scale: 1 - FLIGHT_SHRINK * t,\n rotate: spin * t,\n x: distance * Math.cos(radians) * t,\n y: distance * Math.sin(radians) * t + GRAVITY * distance * t * t,\n opacity: t === 1 ? EXIT_OPACITY : 1,\n };\n }\n\n return {\n phase: \"gone\",\n crush: 1,\n scale: 0,\n rotate: 0,\n x: 0,\n y: 0,\n opacity: 0,\n };\n}\n\nexport interface CrumpleTossProps extends CrumpleTossTiming {\n children: React.ReactNode;\n width: number;\n height: number;\n segments?: number;\n layers?: number;\n randomness?: number;\n}\n\nexport function CrumpleToss({\n children,\n width,\n height,\n segments,\n layers,\n randomness,\n ...timing\n}: CrumpleTossProps) {\n const frame = useCurrentFrame();\n const pose = crumpleTossPose({ frame, ...timing });\n if (pose.phase === \"gone\") return null;\n\n const pieces = crumpleSegments({\n width,\n height,\n segments,\n layers,\n randomness,\n crushTo: timing.crushTo,\n seed: timing.seed,\n });\n const c = pose.crush;\n\n return (\n <div\n style={{\n position: \"relative\",\n width,\n height,\n transformOrigin: \"center\",\n opacity: pose.opacity,\n transform: `translate(${pose.x}px, ${pose.y}px) rotate(${pose.rotate}deg) scale(${pose.scale})`,\n }}\n >\n {pieces.map((piece, i) => (\n <div\n key={`piece:${i}`}\n style={{\n position: \"absolute\",\n inset: 0,\n clipPath: `polygon(${piece.clip.map(([x, y]) => `${x}% ${y}%`).join(\", \")})`,\n transformOrigin: `${piece.origin[0]}% ${piece.origin[1]}%`,\n transform: `translate(${piece.dx * c}px, ${piece.dy * c}px) rotate(${piece.rotate * c}deg) scale(${1 + (piece.scale - 1) * c})`,\n filter:\n c > 0\n ? `drop-shadow(0 0 ${0.6 * c}px rgba(38,36,44,0.55))`\n : undefined,\n }}\n >\n <div style={{ position: \"absolute\", inset: 0 }}>{children}</div>\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: creaseShading(piece, c),\n opacity: c,\n }}\n />\n </div>\n ))}\n </div>\n );\n}\n",+ "type": "registry:component",+ "target": "components/remocn/crumple-toss.tsx"+ }+ ],+ "type": "registry:component"+}diff --git a/registry-artifacts/registry.json b/registry-artifacts/registry.jsonindex eee911d5..81bebeeb 100644--- a/registry-artifacts/registry.json+++ b/registry-artifacts/registry.json@@ -1402,6 +1402,21 @@],"type": "registry:component"},+ {+ "name": "crumple-toss",+ "title": "Crumple Toss",+ "description": "Crushes an element into a ball of paper and throws it out of frame on an arc, leaving the scene around it running.",+ "dependencies": ["remotion"],+ "registryDependencies": ["@remocn/stop-motion"],+ "files": [+ {+ "path": "registry/remocn/crumple-toss/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/crumple-toss.tsx"+ }+ ],+ "type": "registry:component"+ },{"name": "scribble-circle","title": "Scribble Circle",diff --git a/registry/__index__.tsx b/registry/__index__.tsxindex a8099011..99113023 100644--- a/registry/__index__.tsx+++ b/registry/__index__.tsx@@ -12,6 +12,7 @@ import { checkListConfig } from "@/registry/remocn/check-list/config";import { claudeChatConfig } from "@/registry/remocn/claude-chat/config";import { claudeCodeConfig } from "@/registry/remocn/claude-code/config";import { confettiConfig } from "@/registry/remocn/confetti/config";+import { crumpleTossConfig } from "@/registry/remocn/crumple-toss/config";import { dataFlowPipesConfig } from "@/registry/remocn/data-flow-pipes/config";import { ditherDissolveConfig } from "@/registry/remocn/dither-dissolve/config";import { driftConfig } from "@/registry/remocn/drift/config";@@ -1574,6 +1575,13 @@ const registry: Record<string, RegistryEntry> = {})),config: checkListConfig,},+ "crumple-toss": {+ load: () =>+ import("@/components/docs/examples/crumple-toss-example").then((m) => ({+ default: m.CrumpleTossExampleScene,+ })),+ config: crumpleTossConfig,+ },"scribble-circle": {load: () =>import("@/components/docs/examples/scribble-circle-example").then(diff --git a/registry/remocn/crumple-toss/__tests__/crumple-toss.test.ts b/registry/remocn/crumple-toss/__tests__/crumple-toss.test.tsnew file mode 100644index 00000000..420541ae--- /dev/null+++ b/registry/remocn/crumple-toss/__tests__/crumple-toss.test.ts@@ -0,0 +1,494 @@+import { describe, expect, it } from "bun:test";++import { crumpleTossConfig } from "../config";+import {+ type CrumpleTossTiming,+ creaseShading,+ crumpleSegments,+ crumpleTossLanding,+ crumpleTossPose,+} from "../index";++const AT = 12;+const BASE = { at: AT, crumpleSteps: 4, tossSteps: 5, step: 3 };+const CARD = { width: 380, height: 220 };++const numberControl = (name: string) => {+ const control = crumpleTossConfig.controls[name];+ if (control.type !== "number") {+ throw new Error(`${name} is not a number control`);+ }+ return control;+};++const controlValues = (name: string) => {+ const { min, max, step } = numberControl(name);+ return Array.from(+ { length: Math.floor((max - min) / step + 1e-9) + 1 },+ (_, i) => min + i * step,+ );+};++const at = (frame: number, timing: CrumpleTossTiming = BASE) =>+ crumpleTossPose({ frame, ...timing });++const posesOf = (phase: string, timing: CrumpleTossTiming = BASE) => {+ const step = timing.step ?? 3;+ const total = (timing.crumpleSteps ?? 4) + (timing.tossSteps ?? 5);+ return Array.from({ length: total }, (_, p) =>+ at(timing.at + p * step, timing),+ ).filter((pose) => pose.phase === phase);+};++const areaOf = (points: [number, number][]) => {+ let sum = 0;+ for (let i = 0; i < points.length; i++) {+ const [x1, y1] = points[i];+ const [x2, y2] = points[(i + 1) % points.length];+ sum += x1 * y2 - x2 * y1;+ }+ return Math.abs(sum) / 2;+};++describe("phases", () => {+ it("does nothing at all before `at`", () => {+ for (const frame of [0, 5, AT - 1]) {+ const pose = at(frame);+ expect(pose.phase).toBe("idle");+ expect(pose.crush).toBe(0);+ expect(pose.scale).toBe(1);+ expect(pose.rotate).toBe(0);+ expect(pose.x).toBe(0);+ expect(pose.y).toBe(0);+ expect(pose.opacity).toBe(1);+ }+ });++ it("uses half-open bounds, so crumpleSteps 4 means exactly four crush poses", () => {+ expect(posesOf("crumple")).toHaveLength(4);+ expect(posesOf("toss")).toHaveLength(5);+ });++ it("lands the boundaries on the right frames for every step", () => {+ for (const step of controlValues("step")) {+ const timing = { ...BASE, step };+ expect(at(AT, timing).phase).toBe("crumple");+ expect(at(AT + 4 * step - 1, timing).phase).toBe("crumple");+ expect(at(AT + 4 * step, timing).phase).toBe("toss");+ expect(at(AT + 9 * step - 1, timing).phase).toBe("toss");+ expect(at(AT + 9 * step, timing).phase).toBe("gone");+ expect(at(AT + 400, timing).phase).toBe("gone");+ }+ });++ it("holds every value constant inside one pose", () => {+ for (const base of [AT, AT + 3, AT + 15]) {+ for (const offset of [0, 1, 2]) {+ expect(at(base + offset)).toEqual(at(base));+ }+ }+ });+});++describe("the crush ramp", () => {+ it("folds the paper progressively and reaches a full crush on the last pose", () => {+ expect(posesOf("crumple").map((p) => p.crush)).toEqual([+ 0.25, 0.5, 0.75, 1,+ ]);+ });++ it("stays fully crushed for the whole flight", () => {+ for (const pose of posesOf("toss")) {+ expect(pose.crush).toBe(1);+ }+ });++ it("reaches a full crush whatever crumpleSteps is", () => {+ for (const crumpleSteps of controlValues("crumpleSteps")) {+ const crush = posesOf("crumple", { ...BASE, crumpleSteps }).map(+ (p) => p.crush,+ );+ expect(crush).toHaveLength(crumpleSteps);+ expect(crush.at(-1)).toBe(1);+ expect(crush[0]).toBeCloseTo(1 / crumpleSteps, 9);+ }+ });+});++describe("the card is cut into segments", () => {+ const pieces = crumpleSegments({ ...CARD, seed: "toss" });++ it("covers the card exactly at rest, so there is no seam to see", () => {+ for (const size of [+ { width: 380, height: 220 },+ { width: 300, height: 300 },+ { width: 600, height: 160 },+ ]) {+ for (const segments of controlValues("segments")) {+ for (const layers of controlValues("layers")) {+ const covered = crumpleSegments({+ ...size,+ segments,+ layers,+ seed: "toss",+ })+ .map((piece) => areaOf(piece.clip))+ .reduce((sum, part) => sum + part, 0);+ expect(covered).toBeCloseTo(100 * 100, 6);+ }+ }+ }+ });++ it("cuts each wedge into one panel per layer", () => {+ for (const segments of controlValues("segments")) {+ for (const layers of controlValues("layers")) {+ expect(crumpleSegments({ ...CARD, segments, layers })).toHaveLength(+ segments * layers,+ );+ }+ }+ });++ it("starts the innermost panel of every wedge at the centre of the card", () => {+ for (const layers of controlValues("layers")) {+ const cut = crumpleSegments({ ...CARD, layers });+ cut.forEach((piece, i) => {+ expect(piece.clip.length).toBeGreaterThanOrEqual(3);+ if (i % layers === 0) {+ expect(piece.clip[0]).toEqual([50, 50]);+ } else {+ expect(piece.clip).not.toContainEqual([50, 50]);+ }+ });+ }+ });++ it("reaches the rim with the outer layer and holds the core back", () => {+ for (const layers of controlValues("layers")) {+ const cut = crumpleSegments({ ...CARD, layers });+ const touchesRim = (piece: { clip: [number, number][] }) =>+ piece.clip.some(+ ([x, y]) => x < 0.01 || x > 99.99 || y < 0.01 || y > 99.99,+ );+ cut.forEach((piece, i) => {+ expect(touchesRim(piece)).toBe(i % layers === layers - 1);+ });+ }+ });++ it("curls each wedge one way, steepening toward the rim", () => {+ for (const seed of ["toss", "a", "b", "c"]) {+ for (const layers of [2, 3]) {+ const cut = crumpleSegments({ ...CARD, layers, seed });+ for (let i = 0; i < cut.length; i += layers) {+ const wedge = cut.slice(i, i + layers).map((p) => p.rotate);+ for (let layer = 1; layer < layers; layer++) {+ expect(Math.sign(wedge[layer])).toBe(Math.sign(wedge[0]));+ expect(Math.abs(wedge[layer])).toBeGreaterThan(+ Math.abs(wedge[layer - 1]),+ );+ }+ const outer = 0.45 + 0.55;+ const core = 0.45 + (0.55 * 1) / layers;+ expect(Math.abs(wedge.at(-1)) / Math.abs(wedge[0])).toBeCloseTo(+ outer / core,+ 9,+ );+ }+ }+ }+ });++ it("pulls every wedge toward the centre rather than pushing it out", () => {+ for (const piece of pieces) {+ const from: [number, number] = [+ (piece.origin[0] / 100) * CARD.width - CARD.width / 2,+ (piece.origin[1] / 100) * CARD.height - CARD.height / 2,+ ];+ expect(settledReach(piece)).toBeLessThan(Math.hypot(from[0], from[1]));+ }+ });++ it("shrinks and tilts each panel, so the paper folds instead of sliding", () => {+ for (const piece of pieces) {+ expect(piece.scale).toBeGreaterThan(0);+ expect(piece.scale).toBeLessThanOrEqual(1);+ expect(Math.abs(piece.rotate)).toBeLessThanOrEqual(46);+ }+ expect(new Set(pieces.map((p) => p.rotate)).size).toBe(pieces.length);+ });++ it("shrinks the rim panels hard, since they have the furthest to fold", () => {+ const layers = 2;+ for (const piece of crumpleSegments({ ...CARD, layers }).filter(+ (_, i) => i % layers === layers - 1,+ )) {+ expect(piece.scale).toBeLessThan(1);+ }+ });++ it("keeps the wad mostly lit, with shadow as the accent", () => {+ for (const segments of controlValues("segments")) {+ const tones = crumpleSegments({ ...CARD, segments }).map((p) => p.tone);+ expect(tones.some((t) => t < 2)).toBe(true);+ expect(tones.some((t) => t >= 2)).toBe(true);+ }+ });++ it("is deterministic per seed and folds differently across seeds", () => {+ expect(crumpleSegments({ ...CARD, seed: "toss" })).toEqual(pieces);+ expect(crumpleSegments({ ...CARD, seed: "other" })).not.toEqual(pieces);+ });++ it("tightens the wad as crushTo drops", () => {+ const wadOf = (crushTo: number) =>+ crumpleSegments({ ...CARD, crushTo }).reduce(+ (sum, piece) => sum + settledReach(piece),+ 0,+ );+ expect(wadOf(0.15)).toBeLessThan(wadOf(0.7));+ });++ it("never cuts fewer than three wedges, whatever the layer count", () => {+ for (const layers of controlValues("layers")) {+ expect(crumpleSegments({ ...CARD, segments: 1, layers })).toHaveLength(+ 3 * layers,+ );+ }+ expect(crumpleSegments({ ...CARD, segments: 9, layers: 0 })).toHaveLength(+ 9,+ );+ });+});++describe("crease shading", () => {+ const piece = { tone: 0, rotate: 30, crease: 0.5 };++ it("breaks each facet into a lit side and a shadowed side", () => {+ const shading = creaseShading(piece, 1);+ expect(shading.startsWith("linear-gradient(")).toBe(true);+ expect(shading).toContain("rgba(255,255,255,0.66) 41.0%");+ expect(shading).toContain("rgba(255,255,255,0.18) 59.0%");+ });++ it("counter-rotates the light so it stays fixed while the facet turns", () => {+ expect(creaseShading(piece, 0)).toContain("-55.0deg");+ expect(creaseShading(piece, 1)).toContain("-85.0deg");+ expect(creaseShading({ ...piece, rotate: -30 }, 1)).toContain("-25.0deg");+ });++ it("keeps the fold inside the facet at every crease value", () => {+ for (const crease of [0, 0.3, 0.5, 0.7, 1]) {+ const stops = [+ ...creaseShading({ ...piece, crease }, 1).matchAll(/([\d.]+)%/g),+ ].map((match) => Number(match[1]));+ expect(stops).toEqual([...stops].sort((a, b) => a - b));+ expect(stops.at(0)).toBeGreaterThanOrEqual(0);+ expect(stops.at(-1)).toBeLessThanOrEqual(100);+ }+ });++ it("gives every tone a real value break, so no facet reads as flat", () => {+ for (let tone = 0; tone < 4; tone++) {+ const shading = creaseShading({ ...piece, tone }, 1);+ const colours = new Set(+ [...shading.matchAll(/rgba\([^)]+\)/g)].map((match) => match[0]),+ );+ expect(colours.size).toBe(2);+ }+ });+});++const settledReach = (piece: {+ origin: [number, number];+ dx: number;+ dy: number;+}) =>+ Math.hypot(+ (piece.origin[0] / 100) * CARD.width - CARD.width / 2 + piece.dx,+ (piece.origin[1] / 100) * CARD.height - CARD.height / 2 + piece.dy,+ );++describe("fold randomness", () => {+ it("folds perfectly regularly at zero, with no tilt and no crease", () => {+ const layers = 2;+ const pieces = crumpleSegments({ ...CARD, layers, randomness: 0 });+ for (const piece of pieces) {+ expect(Math.abs(piece.rotate)).toBe(0);+ expect(piece.crease).toBe(0.5);+ }+ for (let layer = 0; layer < layers; layer++) {+ const reaches = pieces+ .filter((_, i) => i % layers === layer)+ .map(settledReach);+ for (const reach of reaches) {+ expect(reach).toBeCloseTo(reaches[0], 6);+ }+ }+ });++ it("settles the core nearer the middle than the rim panels", () => {+ const layers = 3;+ const pieces = crumpleSegments({ ...CARD, layers, randomness: 0 });+ const depthOf = (layer: number) =>+ settledReach(pieces.filter((_, i) => i % layers === layer)[0]);+ expect(depthOf(0)).toBeLessThan(depthOf(1));+ expect(depthOf(1)).toBeLessThan(depthOf(2));+ });++ it("ignores the seed entirely at zero, so nothing random is left", () => {+ expect(crumpleSegments({ ...CARD, randomness: 0, seed: "a" })).toEqual(+ crumpleSegments({ ...CARD, randomness: 0, seed: "b" }),+ );+ expect(crumpleSegments({ ...CARD, seed: "a" })).not.toEqual(+ crumpleSegments({ ...CARD, seed: "b" }),+ );+ });++ it("scatters tilt, reach and panel size as it rises", () => {+ const spreadOf = (randomness: number) => {+ const pieces = crumpleSegments({ ...CARD, randomness });+ const reaches = pieces.map(settledReach);+ return {+ tilt: Math.max(...pieces.map((p) => Math.abs(p.rotate))),+ reach: Math.max(...reaches) - Math.min(...reaches),+ size:+ Math.max(...pieces.map((p) => p.scale)) -+ Math.min(...pieces.map((p) => p.scale)),+ };+ };+ const calm = spreadOf(0.2);+ const wild = spreadOf(1);+ expect(wild.tilt).toBeGreaterThan(calm.tilt);+ expect(wild.reach).toBeGreaterThan(calm.reach);+ expect(wild.size).toBeGreaterThan(calm.size);+ });++ it("still covers the card exactly at every randomness", () => {+ for (const randomness of controlValues("randomness")) {+ const covered = crumpleSegments({ ...CARD, randomness })+ .map((piece) => areaOf(piece.clip))+ .reduce((sum, part) => sum + part, 0);+ expect(covered).toBeCloseTo(100 * 100, 6);+ }+ });++ it("clamps values outside the range instead of inverting the fold", () => {+ expect(crumpleSegments({ ...CARD, randomness: -3 })).toEqual(+ crumpleSegments({ ...CARD, randomness: 0 }),+ );+ expect(crumpleSegments({ ...CARD, randomness: 9 })).toEqual(+ crumpleSegments({ ...CARD, randomness: 1 }),+ );+ });+});++describe("the throw arc", () => {+ const flight = (timing: CrumpleTossTiming = BASE) => posesOf("toss", timing);++ it("throws right for a forward angle and left past ninety degrees", () => {+ expect(flight({ ...BASE, direction: -35 }).at(-1).x).toBeGreaterThan(0);+ expect(flight({ ...BASE, direction: 150 }).at(-1).x).toBeLessThan(0);+ expect(flight({ ...BASE, direction: 90 }).at(-1).x).toBeCloseTo(0, 6);+ });++ it("matches the plan's landing point at the defaults", () => {+ const landed = flight().at(-1);+ expect(landed.x).toBeCloseTo(737, 0);+ expect(landed.y).toBeCloseTo(294, 0);+ });++ it("rises before it falls at a clearly upward angle", () => {+ for (const direction of [-15, -35, -60]) {+ const ys = flight({ ...BASE, tossSteps: 5, direction }).map((p) => p.y);+ expect(ys[0]).toBeLessThan(0);+ expect(ys.at(-1)).toBeGreaterThan(0);+ }+ });++ it("peaks in the first half of the flight and rises at least 8% of distance", () => {+ const ys = flight().map((p) => p.y);+ const peak = Math.min(...ys);+ expect(ys.indexOf(peak)).toBeLessThan(ys.length / 2);+ expect(-peak / 900).toBeGreaterThanOrEqual(0.08);+ expect(-peak).toBeCloseTo(76.9, 1);+ });++ it("reports the landing point the flight actually reaches", () => {+ for (const direction of [-60, -35, 0, 150]) {+ for (const distance of [200, 440, 900, 1600]) {+ const landed = flight({ ...BASE, direction, distance }).at(-1);+ const predicted = crumpleTossLanding({ direction, distance });+ expect(predicted.x).toBeCloseTo(landed.x, 9);+ expect(predicted.y).toBeCloseTo(landed.y, 9);+ }+ }+ });++ it("predicts the landing from the same defaults the component uses", () => {+ const landed = flight().at(-1);+ expect(crumpleTossLanding().x).toBeCloseTo(landed.x, 9);+ expect(crumpleTossLanding().y).toBeCloseTo(landed.y, 9);+ });++ it("keeps the arc shape at any distance", () => {+ const shapeOf = (distance: number) =>+ flight({ ...BASE, distance }).map((p) => p.y / distance);+ expect(shapeOf(200)).toEqual(shapeOf(1600));+ });++ it("tumbles through the full spin and pulls away as it goes", () => {+ const poses = flight();+ expect(poses.at(-1).rotate).toBeCloseTo(220, 6);+ for (let i = 1; i < poses.length; i++) {+ expect(poses[i].rotate).toBeGreaterThan(poses[i - 1].rotate);+ expect(poses[i].scale).toBeLessThan(poses[i - 1].scale);+ }+ });++ it("steps the opacity once at the exit instead of fading", () => {+ const opacities = flight().map((p) => p.opacity);+ expect(opacities.slice(0, -1).every((o) => o === 1)).toBe(true);+ expect(opacities.at(-1)).toBe(0.4);+ expect(new Set(opacities).size).toBe(2);+ });+});++describe("crumpleTossConfig", () => {+ it("reaches leftward throws, which a -90..90 range could not", () => {+ const direction = numberControl("direction");+ expect(direction.min).toBe(-180);+ expect(direction.max).toBe(180);+ expect(Math.cos((direction.min * Math.PI) / 180)).toBeLessThan(0);+ });++ it("fits the default beat with room to read the empty frame", () => {+ const step = numberControl("step").default;+ const settles =+ numberControl("at").default ++ (numberControl("crumpleSteps").default ++ numberControl("tossSteps").default) *+ step;+ expect(settles).toBe(33);+ expect(crumpleTossConfig.durationInFrames - settles).toBeGreaterThanOrEqual(+ 30,+ );+ });++ it("records where a maxed-out slider outruns the preview", () => {+ const fits = (+ start: number,+ crumpleSteps: number,+ tossSteps: number,+ step: number,+ ) =>+ start + (crumpleSteps + tossSteps) * step <=+ crumpleTossConfig.durationInFrames;+ const start = numberControl("at");+ expect(fits(start.default, 4, 5, 3)).toBe(true);+ expect(fits(start.max, 4, 5, 3)).toBe(true);+ expect(fits(start.default, 8, 10, 3)).toBe(true);+ expect(fits(start.max, 8, 10, 6)).toBe(false);+ });+});diff --git a/registry/remocn/crumple-toss/config.ts b/registry/remocn/crumple-toss/config.tsnew file mode 100644index 00000000..dc9e2856--- /dev/null+++ b/registry/remocn/crumple-toss/config.ts@@ -0,0 +1,104 @@+import { crumpleTossExampleCode } from "@/components/docs/examples/crumple-toss-example";+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";++export const crumpleTossConfig: ComponentConfig = {+ componentName: "CrumpleToss",+ importPath: "@/components/remocn/crumple-toss",+ controls: {+ at: {+ type: "number",+ default: 6,+ min: 0,+ max: 24,+ step: 3,+ label: "Crumple starts",+ },+ crumpleSteps: {+ type: "number",+ default: 4,+ min: 2,+ max: 8,+ step: 1,+ label: "Crush poses",+ },+ tossSteps: {+ type: "number",+ default: 5,+ min: 2,+ max: 10,+ step: 1,+ label: "Flight poses",+ },+ direction: {+ type: "number",+ default: -35,+ min: -180,+ max: 180,+ step: 5,+ label: "Throw angle",+ },+ distance: {+ type: "number",+ default: 440,+ min: 200,+ max: 1600,+ step: 20,+ label: "Arc scale",+ },+ spin: {+ type: "number",+ default: 220,+ min: 0,+ max: 720,+ step: 10,+ label: "Tumble",+ },+ segments: {+ type: "number",+ default: 9,+ min: 5,+ max: 14,+ step: 1,+ label: "Paper segments",+ },+ layers: {+ type: "number",+ default: 2,+ min: 1,+ max: 3,+ step: 1,+ label: "Fold layers",+ },+ randomness: {+ type: "number",+ default: 0.6,+ min: 0,+ max: 1,+ step: 0.05,+ label: "Fold randomness",+ },+ crushTo: {+ type: "number",+ default: 0.34,+ min: 0.15,+ max: 0.7,+ step: 0.01,+ label: "Wad size",+ },+ seed: { type: "text", default: "toss", label: "Seed" },+ step: {+ type: "number",+ default: 3,+ min: 1,+ max: 6,+ step: 1,+ label: "Frames / pose",+ },+ },+ snippet: crumpleTossExampleCode,+ durationInFrames: 90,+ fps: FPS,+ compositionWidth: W,+ compositionHeight: H,+ previewBackdrop: { type: "color", value: "#f1eee7" },+};diff --git a/registry/remocn/crumple-toss/index.tsx b/registry/remocn/crumple-toss/index.tsxnew file mode 100644index 00000000..20ef02ac--- /dev/null+++ b/registry/remocn/crumple-toss/index.tsx@@ -0,0 +1,366 @@+"use client";++import type React from "react";+import { useCurrentFrame } from "remotion";+import { DEFAULT_STEP, hashRange, qstep } from "@/lib/remocn/stop-motion";++const GRAVITY = 0.9;+const FLIGHT_SHRINK = 0.5;+const EXIT_OPACITY = 0.4;++const FOLD_TILT = 46;+const WAD_REACH = 0.27;+const WAD_SPREAD = 0.07;+const ANGLE_JITTER = 0.22;+const SCALE_SPREAD = 0.25;+const DEFAULT_RANDOMNESS = 0.6;+const DEFAULT_LAYERS = 2;+const LAYER_TILT_FLOOR = 0.45;+const FACET_SIZE = 0.5;+const FACET_CAP = 0.5;++const TONE_PATTERN = [0, 1, 3, 1, 0, 2, 1, 2, 0];++const TONES = [+ { lit: "rgba(255,255,255,0.66)", dark: "rgba(255,255,255,0.18)" },+ { lit: "rgba(255,255,255,0.30)", dark: "rgba(38,36,44,0.10)" },+ { lit: "rgba(255,255,255,0.08)", dark: "rgba(38,36,44,0.20)" },+ { lit: "rgba(38,36,44,0.06)", dark: "rgba(38,36,44,0.30)" },+];++const LIGHT_ANGLE = -55;+const CREASE_BLEND = 9;++export type CrumplePhase = "idle" | "crumple" | "toss" | "gone";++export type CrumplePose = {+ phase: CrumplePhase;+ crush: number;+ scale: number;+ rotate: number;+ x: number;+ y: number;+ opacity: number;+};++export type CrumpleSegment = {+ clip: [number, number][];+ origin: [number, number];+ dx: number;+ dy: number;+ scale: number;+ rotate: number;+ tone: number;+ crease: number;+};++export type CrumpleTossTiming = {+ at: number;+ crumpleSteps?: number;+ tossSteps?: number;+ direction?: number;+ distance?: number;+ spin?: number;+ crushTo?: number;+ seed?: string;+ step?: number;+};++const rayToEdge = (+ angle: number,+ halfWidth: number,+ halfHeight: number,+): [number, number] => {+ const cos = Math.cos(angle);+ const sin = Math.sin(angle);+ const t = Math.min(+ halfWidth / (Math.abs(cos) || 1e-9),+ halfHeight / (Math.abs(sin) || 1e-9),+ );+ return [cos * t, sin * t];+};++const normalize = (angle: number) => {+ const turn = Math.PI * 2;+ return ((angle % turn) + turn) % turn;+};++const shrinkToward = (+ [x, y]: [number, number],+ factor: number,+): [number, number] => [x * factor, y * factor];++const averageOf = (points: [number, number][]): [number, number] => [+ points.reduce((sum, p) => sum + p[0], 0) / points.length,+ points.reduce((sum, p) => sum + p[1], 0) / points.length,+];++export function crumpleSegments(args: {+ width: number;+ height: number;+ segments?: number;+ layers?: number;+ crushTo?: number;+ randomness?: number;+ seed?: string;+}): CrumpleSegment[] {+ const count = Math.max(3, Math.round(args.segments ?? 9));+ const layers = Math.max(1, Math.round(args.layers ?? DEFAULT_LAYERS));+ const crushTo = args.crushTo ?? 0.34;+ const chaos = Math.min(1, Math.max(0, args.randomness ?? DEFAULT_RANDOMNESS));+ const seed = args.seed ?? "toss";+ const halfWidth = args.width / 2;+ const halfHeight = args.height / 2;+ const wad = Math.min(args.width, args.height) * crushTo;++ const angles = Array.from(+ { length: count },+ (_, i) =>+ (i / count) * Math.PI * 2 ++ hashRange(`${seed}:ang${i}`, -ANGLE_JITTER, ANGLE_JITTER) * chaos,+ );++ const corners: [number, number][] = [+ [halfWidth, halfHeight],+ [-halfWidth, halfHeight],+ [-halfWidth, -halfHeight],+ [halfWidth, -halfHeight],+ ];++ const toPercent = ([x, y]: [number, number]): [number, number] => [+ ((x + halfWidth) / args.width) * 100,+ ((y + halfHeight) / args.height) * 100,+ ];++ const panels: CrumpleSegment[] = [];++ angles.forEach((angle, i) => {+ const nextAngle =+ angles[(i + 1) % count] + (i === count - 1 ? Math.PI * 2 : 0);+ const from = rayToEdge(angle, halfWidth, halfHeight);+ const to = rayToEdge(nextAngle, halfWidth, halfHeight);++ const span = normalize(nextAngle - angle);+ const between = corners+ .map((corner): [[number, number], number] => [+ corner,+ normalize(Math.atan2(corner[1], corner[0]) - angle),+ ])+ .filter(([, spanned]) => spanned > 0 && spanned < span)+ .sort((a, b) => a[1] - b[1])+ .map(([corner]) => corner);++ const rim: [number, number][] = [from, ...between, to];++ for (let layer = 0; layer < layers; layer++) {+ const inner = layer / layers;+ const outer = (layer + 1) / layers;+ const depth = (layer + 1) / layers;+ const shape: [number, number][] =+ layer === 0+ ? [[0, 0], ...rim.map((point) => shrinkToward(point, outer))]+ : [+ ...rim.map((point) => shrinkToward(point, outer)),+ ...[...rim].reverse().map((point) => shrinkToward(point, inner)),+ ];++ const centroid = averageOf(shape);+ const extent =+ Math.max(+ ...shape.map((point) =>+ Math.hypot(point[0] - centroid[0], point[1] - centroid[1]),+ ),+ ) || 1;+ const key = `${seed}:${i}:${layer}`;++ const reach =+ wad *+ (WAD_REACH * depth ++ hashRange(`${key}:reach`, -WAD_SPREAD, WAD_SPREAD) * chaos * depth);+ const heading = Math.atan2(centroid[1], centroid[0]);++ panels.push({+ clip: shape.map(toPercent),+ origin: toPercent(centroid),+ dx: Math.cos(heading) * reach - centroid[0],+ dy: Math.sin(heading) * reach - centroid[1],+ scale:+ Math.min(FACET_CAP, (wad * FACET_SIZE) / extent) *+ (1 + hashRange(`${key}:size`, -SCALE_SPREAD, SCALE_SPREAD) * chaos),+ rotate:+ chaos === 0+ ? 0+ : hashRange(`${seed}:tilt${i}`, -FOLD_TILT, FOLD_TILT) *+ chaos *+ (LAYER_TILT_FLOOR + (1 - LAYER_TILT_FLOOR) * depth),+ tone: Math.min(+ TONES.length - 1,+ TONE_PATTERN[panels.length % TONE_PATTERN.length] ++ Math.ceil((1 - depth) * 2),+ ),+ crease: 0.5 + hashRange(`${key}:crease`, -0.2, 0.2) * chaos,+ });+ }+ });++ return panels;+}++export function creaseShading(+ piece: Pick<CrumpleSegment, "tone" | "rotate" | "crease">,+ crush: number,+): string {+ const tone = TONES[piece.tone];+ const fold = piece.crease * 100;+ const lit = Math.max(0, fold - CREASE_BLEND).toFixed(1);+ const dark = Math.min(100, fold + CREASE_BLEND).toFixed(1);+ const angle = (LIGHT_ANGLE - piece.rotate * crush).toFixed(1);+ return `linear-gradient(${angle}deg, ${tone.lit} 0%, ${tone.lit} ${lit}%, ${tone.dark} ${dark}%, ${tone.dark} 100%)`;+}++export function crumpleTossLanding(options?: {+ direction?: number;+ distance?: number;+}): { x: number; y: number } {+ const distance = options?.distance ?? 900;+ const radians = ((options?.direction ?? -35) * Math.PI) / 180;+ return {+ x: distance * Math.cos(radians),+ y: distance * Math.sin(radians) + GRAVITY * distance,+ };+}++export function crumpleTossPose(+ args: CrumpleTossTiming & { frame: number },+): CrumplePose {+ const crumpleSteps = args.crumpleSteps ?? 4;+ const tossSteps = args.tossSteps ?? 5;+ const direction = args.direction ?? -35;+ const distance = args.distance ?? 900;+ const spin = args.spin ?? 220;+ const step = args.step ?? DEFAULT_STEP;++ if (args.frame < args.at) {+ return {+ phase: "idle",+ crush: 0,+ scale: 1,+ rotate: 0,+ x: 0,+ y: 0,+ opacity: 1,+ };+ }++ const pose = qstep(args.frame - args.at, step);++ if (pose < crumpleSteps) {+ return {+ phase: "crumple",+ crush: (pose + 1) / crumpleSteps,+ scale: 1,+ rotate: 0,+ x: 0,+ y: 0,+ opacity: 1,+ };+ }++ if (pose < crumpleSteps + tossSteps) {+ const t = (pose - crumpleSteps + 1) / tossSteps;+ const radians = (direction * Math.PI) / 180;+ return {+ phase: "toss",+ crush: 1,+ scale: 1 - FLIGHT_SHRINK * t,+ rotate: spin * t,+ x: distance * Math.cos(radians) * t,+ y: distance * Math.sin(radians) * t + GRAVITY * distance * t * t,+ opacity: t === 1 ? EXIT_OPACITY : 1,+ };+ }++ return {+ phase: "gone",+ crush: 1,+ scale: 0,+ rotate: 0,+ x: 0,+ y: 0,+ opacity: 0,+ };+}++export interface CrumpleTossProps extends CrumpleTossTiming {+ children: React.ReactNode;+ width: number;+ height: number;+ segments?: number;+ layers?: number;+ randomness?: number;+}++export function CrumpleToss({+ children,+ width,+ height,+ segments,+ layers,+ randomness,+ ...timing+}: CrumpleTossProps) {+ const frame = useCurrentFrame();+ const pose = crumpleTossPose({ frame, ...timing });+ if (pose.phase === "gone") return null;++ const pieces = crumpleSegments({+ width,+ height,+ segments,+ layers,+ randomness,+ crushTo: timing.crushTo,+ seed: timing.seed,+ });+ const c = pose.crush;++ return (+ <div+ style={{+ position: "relative",+ width,+ height,+ transformOrigin: "center",+ opacity: pose.opacity,+ transform: `translate(${pose.x}px, ${pose.y}px) rotate(${pose.rotate}deg) scale(${pose.scale})`,+ }}+ >+ {pieces.map((piece, i) => (+ <div+ key={`piece:${i}`}+ style={{+ position: "absolute",+ inset: 0,+ clipPath: `polygon(${piece.clip.map(([x, y]) => `${x}% ${y}%`).join(", ")})`,+ transformOrigin: `${piece.origin[0]}% ${piece.origin[1]}%`,+ transform: `translate(${piece.dx * c}px, ${piece.dy * c}px) rotate(${piece.rotate * c}deg) scale(${1 + (piece.scale - 1) * c})`,+ filter:+ c > 0+ ? `drop-shadow(0 0 ${0.6 * c}px rgba(38,36,44,0.55))`+ : undefined,+ }}+ >+ <div style={{ position: "absolute", inset: 0 }}>{children}</div>+ <div+ style={{+ position: "absolute",+ inset: 0,+ background: creaseShading(piece, c),+ opacity: c,+ }}+ />+ </div>+ ))}+ </div>+ );+}diff --git a/registry/remocn/registry.json b/registry/remocn/registry.jsonindex df1bb6d8..6147a555 100644--- a/registry/remocn/registry.json+++ b/registry/remocn/registry.json@@ -1402,6 +1402,21 @@}]},+ {+ "name": "crumple-toss",+ "type": "registry:component",+ "title": "Crumple Toss",+ "description": "Crushes an element into a ball of paper and throws it out of frame on an arc, leaving the scene around it running.",+ "dependencies": ["remotion"],+ "registryDependencies": ["@remocn/stop-motion"],+ "files": [+ {+ "path": "crumple-toss/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/crumple-toss.tsx"+ }+ ]+ },{"name": "scribble-circle","type": "registry:component",