Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: brush arrow
kapishdima726cf8cc4605
diff --git a/components/docs/examples/ink-arrow-example.tsx b/components/docs/examples/ink-arrow-example.tsxindex 6e9b133a..bb9881c4 100644--- a/components/docs/examples/ink-arrow-example.tsx+++ b/components/docs/examples/ink-arrow-example.tsx@@ -9,13 +9,31 @@ const PENCIL = "rgba(38,36,44,0.55)";const FONT_FAMILY ="var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif";-const FROM = { x: 20, y: 20 };-const TO = { x: 300, y: 210 };+const CARD_WIDTH = 420;+const CARD_HEIGHT = 112;+const HEAD_CLEARANCE = 64;+const GROUP_HEIGHT = 380;++const LABEL_SIZE = 40;+const LABEL_WIDTH = 220;+const LABEL_HEIGHT = Math.round(LABEL_SIZE * 1.2);+const LABEL_GAP = 28;++const CARD_TOP = (GROUP_HEIGHT - CARD_HEIGHT) / 2;++const FROM = { x: LABEL_WIDTH / 2, y: LABEL_HEIGHT + LABEL_GAP };+const TO = { x: 328, y: CARD_TOP + CARD_HEIGHT / 2 };++const CARD_LEFT = TO.x + HEAD_CLEARANCE;+const GROUP_WIDTH = CARD_LEFT + CARD_WIDTH;export function InkArrowExampleScene({curvature,color,strokeWidth,+ pressure,+ release,+ grain,drawDur,headSize,headDur,@@ -25,6 +43,9 @@ export function InkArrowExampleScene({curvature?: number;color?: string;strokeWidth?: number;+ pressure?: number;+ release?: number;+ grain?: number;drawDur?: number;headSize?: number;headDur?: number;@@ -32,54 +53,76 @@ export function InkArrowExampleScene({step?: number;}) {return (- <AbsoluteFill>+ <AbsoluteFill style={{ alignItems: "center", justifyContent: "center" }}><divstyle={{- position: "absolute",- left: 200,- top: 150,- fontFamily: FONT_FAMILY,- fontSize: 52,- fontWeight: 600,- color: INK,+ position: "relative",+ width: GROUP_WIDTH,+ height: GROUP_HEIGHT,}}>- Start here- </div>-- <div style={{ position: "absolute", left: 300, top: 210 }}>- <InkArrow- from={FROM}- to={TO}- curvature={curvature}- color={color}- strokeWidth={strokeWidth}- drawDur={drawDur}- headSize={headSize}- headDur={headDur}- seed={seed}- step={step}- />- </div>+ <div+ style={{+ position: "absolute",+ left: 0,+ top: 0,+ width: LABEL_WIDTH,+ height: LABEL_HEIGHT,+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ fontFamily: FONT_FAMILY,+ fontSize: LABEL_SIZE,+ fontWeight: 600,+ color: INK,+ }}+ >+ Start here+ </div>- <div- style={{- position: "absolute",- left: 600,- top: 400,- background: "#fdfcf8",- border: "1px solid rgba(38,36,44,0.12)",- borderRadius: 4,- padding: "24px 32px",- boxShadow: "0 8px 20px rgba(38,36,44,0.12)",- fontFamily: FONT_FAMILY,- }}- >- <div style={{ fontSize: 28, fontWeight: 600, color: INK }}>- The thing it points at+ <div style={{ position: "absolute", left: 0, top: 0 }}>+ <InkArrow+ from={FROM}+ to={TO}+ curvature={curvature}+ color={color}+ strokeWidth={strokeWidth}+ pressure={pressure}+ release={release}+ grain={grain}+ drawDur={drawDur}+ headSize={headSize}+ headDur={headDur}+ seed={seed}+ step={step}+ /></div>- <div style={{ fontSize: 18, color: PENCIL, marginTop: 6 }}>- Positioned by you, drawn by the pen++ <div+ style={{+ position: "absolute",+ left: CARD_LEFT,+ top: CARD_TOP,+ width: CARD_WIDTH,+ height: CARD_HEIGHT,+ display: "flex",+ flexDirection: "column",+ justifyContent: "center",+ boxSizing: "border-box",+ background: "#fdfcf8",+ border: "1px solid rgba(38,36,44,0.12)",+ borderRadius: 4,+ padding: "0 32px",+ boxShadow: "0 8px 20px rgba(38,36,44,0.12)",+ fontFamily: FONT_FAMILY,+ }}+ >+ <div style={{ fontSize: 28, fontWeight: 600, color: INK }}>+ The thing it points at+ </div>+ <div style={{ fontSize: 18, color: PENCIL, marginTop: 6 }}>+ Positioned by you, drawn by the pen+ </div></div></div></AbsoluteFill>@@ -91,7 +134,10 @@ export const inkArrowExampleCode = (): string => {const curvature = (values.curvature as number) ?? 0.35;const color = (values.color as string) ?? "#26242c";- const strokeWidth = (values.strokeWidth as number) ?? 3;+ const strokeWidth = (values.strokeWidth as number) ?? 8;+ const pressure = (values.pressure as number) ?? 0.2;+ const release = (values.release as number) ?? 1;+ const grain = (values.grain as number) ?? 1;const drawDur = (values.drawDur as number) ?? 36;const headSize = (values.headSize as number) ?? 24;const headDur = (values.headDur as number) ?? 12;@@ -99,20 +145,46 @@ export const inkArrowExampleCode = (const step = (values.step as number) ?? 3;return `import { InkArrow } from "@/components/remocn/ink-arrow";+const to = { x: ${TO.x}, y: ${TO.y} };+const headClearance = ${HEAD_CLEARANCE};+export const MyScene = () => (- <div style={{ position: "absolute", left: 300, top: 210 }}>- <InkArrow- from={{ x: ${FROM.x}, y: ${FROM.y} }}- to={{ x: ${TO.x}, y: ${TO.y} }}- curvature={${curvature}}- color="${color}"- strokeWidth={${strokeWidth}}- drawDur={${drawDur}}- headSize={${headSize}}- headDur={${headDur}}- seed="${seed}"- step={${step}}- />+ <div+ style={{+ position: "relative",+ width: ${GROUP_WIDTH},+ height: ${GROUP_HEIGHT},+ }}+ >+ <div style={{ position: "absolute", left: 0, top: 0 }}>+ <InkArrow+ from={{ x: ${FROM.x}, y: ${FROM.y} }}+ to={to}+ curvature={${curvature}}+ color="${color}"+ strokeWidth={${strokeWidth}}+ pressure={${pressure}}+ release={${release}}+ grain={${grain}}+ drawDur={${drawDur}}+ headSize={${headSize}}+ headDur={${headDur}}+ seed="${seed}"+ step={${step}}+ />+ </div>++ <div+ style={{+ position: "absolute",+ left: to.x + headClearance,+ top: ${CARD_TOP},+ width: ${CARD_WIDTH},+ height: ${CARD_HEIGHT},+ }}+ >+ <YourCard />+ </div></div>);`;};diff --git a/components/docs/examples/ink-underline-example.tsx b/components/docs/examples/ink-underline-example.tsxindex 44e6e44d..f818f040 100644--- a/components/docs/examples/ink-underline-example.tsx+++ b/components/docs/examples/ink-underline-example.tsx@@ -15,6 +15,9 @@ export function InkUnderlineExampleScene({width = 420,color,thickness,+ pressure,+ release,+ grain,durationSteps,seed,step,@@ -22,6 +25,9 @@ export function InkUnderlineExampleScene({width?: number;color?: string;thickness?: number;+ pressure?: number;+ release?: number;+ grain?: number;durationSteps?: number;seed?: string;step?: number;@@ -45,6 +51,9 @@ export function InkUnderlineExampleScene({width={width}color={color}thickness={thickness}+ pressure={pressure}+ release={release}+ grain={grain}delay={written}durationSteps={durationSteps}seed={seed}@@ -60,6 +69,9 @@ export const inkUnderlineExampleCode = (const width = (values.width as number) ?? 420;const color = (values.color as string) ?? "#6f7f35";const thickness = (values.thickness as number) ?? 9;+ const pressure = (values.pressure as number) ?? 1;+ const release = (values.release as number) ?? 0.15;+ const grain = (values.grain as number) ?? 1;const durationSteps = (values.durationSteps as number) ?? 5;const seed = (values.seed as string) ?? "ink";const step = (values.step as number) ?? 3;@@ -81,6 +93,9 @@ export const MyScene = () => (width={${width}}color="${color}"thickness={${thickness}}+ pressure={${pressure}}+ release={${release}}+ grain={${grain}}delay={handwriteDuration(url, { step: ${step} })}durationSteps={${durationSteps}}seed="${seed}"diff --git a/content/docs/effects/ink-arrow.mdx b/content/docs/effects/ink-arrow.mdxindex f402629d..517e70e1 100644--- a/content/docs/effects/ink-arrow.mdx+++ b/content/docs/effects/ink-arrow.mdx@@ -88,8 +88,26 @@ always gives the same hand.{name: "strokeWidth",type: "number",- default: "3",- description: "Pen width in pixels",+ default: "8",+ description: "Brush width in pixels at full pressure",+ },+ {+ name: "pressure",+ type: "number",+ default: "0.2",+ description: "Weight the brush opens on, as a fraction of strokeWidth",+ },+ {+ name: "release",+ type: "number",+ default: "1",+ description: "Weight the brush reaches at the head; above pressure the shaft thickens as it travels",+ },+ {+ name: "grain",+ type: "number",+ default: "1",+ description: "Edge roughness; breaks the thin opening into dry-brush flecks, 0 gives clean edges",},{name: "delay",@@ -107,7 +125,7 @@ always gives the same hand.name: "headSize",type: "number",default: "24",- description: "Length of each head stroke in pixels",+ description: "Length of each head stroke in pixels; a floor, never shrinking below what the brush width needs",},{name: "headDur",diff --git a/content/docs/typography/ink-underline.mdx b/content/docs/typography/ink-underline.mdxindex 2f96ca50..946b6df9 100644--- a/content/docs/typography/ink-underline.mdx+++ b/content/docs/typography/ink-underline.mdx@@ -81,7 +81,25 @@ stop-motion poses the drag takes, so the real length in frames isname: "thickness",type: "number",default: "9",- description: "Stroke width in pixels",+ description: "Brush width in pixels at full pressure",+ },+ {+ name: "pressure",+ type: "number",+ default: "1",+ description: "Weight the brush lands on, as a fraction of thickness",+ },+ {+ name: "release",+ type: "number",+ default: "0.15",+ description: "Weight the brush lifts off at; below pressure it thins into a dry tail",+ },+ {+ name: "grain",+ type: "number",+ default: "1",+ description: "Edge roughness; breaks the thin tail into dry-brush flecks, 0 gives clean edges",},{name: "delay",diff --git a/registry-artifacts/brush.json b/registry-artifacts/brush.jsonnew file mode 100644index 00000000..359da934--- /dev/null+++ b/registry-artifacts/brush.json@@ -0,0 +1,16 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "brush",+ "title": "Brush",+ "description": "Variable-width brush ribbons for Remotion. Pressure taper, grain displacement, and spine samplers shared by the ink marks.",+ "registryDependencies": ["@remocn/stop-motion"],+ "files": [+ {+ "path": "registry/remocn/brush/index.tsx",+ "content": "\"use client\";\n\nimport { hash01 } from \"@/lib/remocn/stop-motion\";\n\nconst GRAIN_RATIO = 0.5;\nconst GRAIN_FREQUENCY = 0.7;\nconst GRAIN_OCTAVES = 3;\n\nexport type BrushPoint = { x: number; y: number };\n\nexport type BrushTaper = {\n strokeWidth: number;\n pressure?: number;\n release?: number;\n};\n\nexport function brushHalfWidth(taper: BrushTaper, t: number): number {\n const pressure = taper.pressure ?? 0.2;\n const release = taper.release ?? 1;\n return (taper.strokeWidth / 2) * (pressure + (release - pressure) * t);\n}\n\nexport function brushGrainScale(strokeWidth: number, grain: number): number {\n return strokeWidth * GRAIN_RATIO * grain;\n}\n\nexport function brushReach(strokeWidth: number, grain: number): number {\n return strokeWidth / 2 + brushGrainScale(strokeWidth, grain) / 2;\n}\n\nexport function brushFilterId(\n seed: string,\n strokeWidth: number,\n grain: number,\n): string {\n return `remocn-brush-${Math.floor(hash01(`${seed}:${strokeWidth}:${grain}`) * 1e9)}`;\n}\n\nexport function sampleCubic(\n from: BrushPoint,\n c1: BrushPoint,\n c2: BrushPoint,\n to: BrushPoint,\n points = 32,\n): BrushPoint[] {\n const count = Math.max(2, points);\n return Array.from({ length: count }, (_, i) => {\n const t = i / (count - 1);\n const u = 1 - t;\n const a = u * u * u;\n const b = 3 * u * u * t;\n const c = 3 * u * t * t;\n const d = t * t * t;\n return {\n x: a * from.x + b * c1.x + c * c2.x + d * to.x,\n y: a * from.y + b * c1.y + c * c2.y + d * to.y,\n };\n });\n}\n\nexport function sampleLine(\n from: BrushPoint,\n to: BrushPoint,\n points = 8,\n): BrushPoint[] {\n const count = Math.max(2, points);\n return Array.from({ length: count }, (_, i) => {\n const t = i / (count - 1);\n return {\n x: from.x + (to.x - from.x) * t,\n y: from.y + (to.y - from.y) * t,\n };\n });\n}\n\nconst normalAt = (points: BrushPoint[], i: number): BrushPoint => {\n const before = points[i - 1] ?? points[i];\n const after = points[i + 1] ?? points[i];\n const tx = after.x - before.x;\n const ty = after.y - before.y;\n const length = Math.hypot(tx, ty) || 1;\n return { x: -ty / length, y: tx / length };\n};\n\nconst curveSegments = (points: BrushPoint[]): string =>\n points\n .slice(0, -1)\n .map((p1, i) => {\n const p0 = points[i - 1] ?? p1;\n const p2 = points[i + 1];\n const p3 = points[i + 2] ?? p2;\n return `C ${p1.x + (p2.x - p0.x) / 6} ${p1.y + (p2.y - p0.y) / 6}, ${p2.x - (p3.x - p1.x) / 6} ${p2.y - (p3.y - p1.y) / 6}, ${p2.x} ${p2.y}`;\n })\n .join(\" \");\n\nexport function brushRibbon(\n spine: BrushPoint[],\n options: BrushTaper & { progress?: number },\n): string {\n const progress = options.progress ?? 1;\n const drawn = Math.max(2, Math.round(progress * (spine.length - 1)) + 1);\n\n const left: BrushPoint[] = [];\n const right: BrushPoint[] = [];\n for (let i = 0; i < drawn; i++) {\n const half = brushHalfWidth(options, i / (spine.length - 1));\n const normal = normalAt(spine, i);\n left.push({\n x: spine[i].x + normal.x * half,\n y: spine[i].y + normal.y * half,\n });\n right.push({\n x: spine[i].x - normal.x * half,\n y: spine[i].y - normal.y * half,\n });\n }\n const back = right.slice().reverse();\n\n return `M ${left[0].x} ${left[0].y} ${curveSegments(left)} L ${back[0].x} ${back[0].y} ${curveSegments(back)} Z`;\n}\n\nexport function BrushGrain({\n seed,\n strokeWidth,\n grain,\n}: {\n seed: string;\n strokeWidth: number;\n grain: number;\n}) {\n return (\n <defs>\n <filter\n id={brushFilterId(seed, strokeWidth, grain)}\n x=\"-30%\"\n y=\"-30%\"\n width=\"160%\"\n height=\"160%\"\n >\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency={GRAIN_FREQUENCY}\n numOctaves={GRAIN_OCTAVES}\n seed={Math.floor(hash01(`${seed}:grain`) * 1000)}\n result=\"brushGrain\"\n />\n <feDisplacementMap\n in=\"SourceGraphic\"\n in2=\"brushGrain\"\n scale={brushGrainScale(strokeWidth, grain)}\n xChannelSelector=\"R\"\n yChannelSelector=\"G\"\n />\n </filter>\n </defs>\n );\n}\n",+ "type": "registry:component",+ "target": "components/remocn/brush.tsx"+ }+ ],+ "type": "registry:component"+}diff --git a/registry-artifacts/ink-arrow.json b/registry-artifacts/ink-arrow.jsonindex f8cd18cf..89a65780 100644--- a/registry-artifacts/ink-arrow.json+++ b/registry-artifacts/ink-arrow.json@@ -2,13 +2,13 @@"$schema": "https://ui.shadcn.com/schema/registry-item.json","name": "ink-arrow","title": "Ink Arrow",- "description": "A hand-drawn arrow that draws itself from one point to another in stop-motion poses, with the head popping on the final pose.",+ "description": "A hand-drawn brush arrow that sweeps itself from one point to another, thickening into the head that pops on the final poses.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "registry/remocn/ink-arrow/index.tsx",- "content": "\"use client\";\n\nimport { useCurrentFrame } from \"remotion\";\nimport { DEFAULT_STEP, hashRange, steppedRamp } from \"@/lib/remocn/stop-motion\";\n\nconst easeOutCubic = (t: number) => 1 - (1 - t) ** 3;\n\nconst HEAD_ANGLE = 0.6;\n\nexport type InkArrowPoint = { x: number; y: number };\n\nexport function inkArrowControls(\n from: InkArrowPoint,\n to: InkArrowPoint,\n curvature: number,\n seed: string,\n): { c1: InkArrowPoint; c2: InkArrowPoint } {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n const distance = Math.hypot(dx, dy) || 1;\n const normalX = -dy / distance;\n const normalY = dx / distance;\n const bow = curvature * distance;\n const wobble = distance * 0.06;\n\n const at = (t: number, key: string): InkArrowPoint => ({\n x:\n from.x +\n dx * t +\n normalX * bow +\n hashRange(`${seed}:${key}:x`, -wobble, wobble),\n y:\n from.y +\n dy * t +\n normalY * bow +\n hashRange(`${seed}:${key}:y`, -wobble, wobble),\n });\n\n return { c1: at(0.3, \"c1\"), c2: at(0.7, \"c2\") };\n}\n\nexport function inkArrowHead(\n c2: InkArrowPoint,\n to: InkArrowPoint,\n headSize: number,\n): { left: InkArrowPoint; right: InkArrowPoint } {\n const dx = to.x - c2.x;\n const dy = to.y - c2.y;\n const length = Math.hypot(dx, dy) || 1;\n const backX = -dx / length;\n const backY = -dy / length;\n\n const arm = (angle: number): InkArrowPoint => ({\n x: to.x + headSize * (backX * Math.cos(angle) - backY * Math.sin(angle)),\n y: to.y + headSize * (backX * Math.sin(angle) + backY * Math.cos(angle)),\n });\n\n return { left: arm(HEAD_ANGLE), right: arm(-HEAD_ANGLE) };\n}\n\nexport function inkArrowViewport(\n from: InkArrowPoint,\n to: InkArrowPoint,\n curvature: number,\n headSize: number,\n strokeWidth: number,\n): { width: number; height: number } {\n const distance = Math.hypot(to.x - from.x, to.y - from.y);\n const margin = headSize + Math.abs(curvature) * distance + strokeWidth;\n return {\n width: Math.max(margin, Math.max(from.x, to.x) + margin),\n height: Math.max(margin, Math.max(from.y, to.y) + margin),\n };\n}\n\nexport interface InkArrowProps {\n from: InkArrowPoint;\n to: InkArrowPoint;\n curvature?: number;\n color?: string;\n strokeWidth?: number;\n delay?: number;\n drawDur?: number;\n headSize?: number;\n headDur?: number;\n seed?: string;\n step?: number;\n}\n\nexport function InkArrow({\n from,\n to,\n curvature = 0.35,\n color = \"#26242c\",\n strokeWidth = 3,\n delay = 0,\n drawDur = 36,\n headSize = 24,\n headDur,\n seed = \"arrow\",\n step = DEFAULT_STEP,\n}: InkArrowProps) {\n const frame = useCurrentFrame();\n const progress = steppedRamp(frame, delay, delay + drawDur, {\n ease: easeOutCubic,\n step,\n });\n const { c1, c2 } = inkArrowControls(from, to, curvature, seed);\n const head = inkArrowHead(c2, to, headSize);\n\n const headFrames = headDur ?? step * 4;\n const headStart = delay + drawDur;\n const headMid = headStart + headFrames / 2;\n const leftArm = steppedRamp(frame, headStart, headMid, {\n ease: easeOutCubic,\n step,\n });\n const rightArm = steppedRamp(frame, headMid, headStart + headFrames, {\n ease: easeOutCubic,\n step,\n });\n\n const { width, height } = inkArrowViewport(\n from,\n to,\n curvature,\n headSize,\n strokeWidth,\n );\n\n return (\n <svg\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n style={{\n display: \"block\",\n overflow: \"visible\",\n opacity: progress > 0 ? 1 : 0,\n }}\n >\n <path\n d={`M ${from.x} ${from.y} C ${c1.x} ${c1.y}, ${c2.x} ${c2.y}, ${to.x} ${to.y}`}\n stroke={color}\n strokeWidth={strokeWidth}\n strokeLinecap=\"round\"\n fill=\"none\"\n pathLength={1}\n strokeDasharray={1}\n strokeDashoffset={1 - progress}\n />\n <path\n d={`M ${to.x} ${to.y} L ${head.left.x} ${head.left.y}`}\n stroke={color}\n strokeWidth={strokeWidth}\n strokeLinecap=\"round\"\n fill=\"none\"\n pathLength={1}\n strokeDasharray={1}\n strokeDashoffset={1 - leftArm}\n />\n <path\n d={`M ${to.x} ${to.y} L ${head.right.x} ${head.right.y}`}\n stroke={color}\n strokeWidth={strokeWidth}\n strokeLinecap=\"round\"\n fill=\"none\"\n pathLength={1}\n strokeDasharray={1}\n strokeDashoffset={1 - rightArm}\n />\n </svg>\n );\n}\n",+ "content": "\"use client\";\n\nimport { useCurrentFrame } from \"remotion\";\nimport {\n BrushGrain,\n type BrushPoint,\n brushFilterId,\n brushReach,\n brushRibbon,\n sampleCubic,\n sampleLine,\n} from \"@/components/remocn/brush\";\nimport { DEFAULT_STEP, hashRange, steppedRamp } from \"@/lib/remocn/stop-motion\";\n\nconst HEAD_ANGLE = 0.72;\nconst SHAFT_SAMPLES = 40;\nconst ARM_SAMPLES = 10;\nconst ARM_TAPER = 0.6;\nconst ARM_OVERSHOOT = 0.16;\nconst HEAD_MIN_RATIO = 2.6;\n\nexport type InkArrowPoint = BrushPoint;\n\nexport function inkArrowControls(\n from: InkArrowPoint,\n to: InkArrowPoint,\n curvature: number,\n seed: string,\n): { c1: InkArrowPoint; c2: InkArrowPoint } {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n const distance = Math.hypot(dx, dy) || 1;\n const normalX = -dy / distance;\n const normalY = dx / distance;\n const bow = curvature * distance;\n const wobble = distance * 0.06;\n\n const at = (t: number, key: string): InkArrowPoint => ({\n x:\n from.x +\n dx * t +\n normalX * bow +\n hashRange(`${seed}:${key}:x`, -wobble, wobble),\n y:\n from.y +\n dy * t +\n normalY * bow +\n hashRange(`${seed}:${key}:y`, -wobble, wobble),\n });\n\n return { c1: at(0.3, \"c1\"), c2: at(0.7, \"c2\") };\n}\n\nexport function inkArrowHead(\n c2: InkArrowPoint,\n to: InkArrowPoint,\n headSize: number,\n): { left: InkArrowPoint; right: InkArrowPoint } {\n const dx = to.x - c2.x;\n const dy = to.y - c2.y;\n const length = Math.hypot(dx, dy) || 1;\n const backX = -dx / length;\n const backY = -dy / length;\n\n const arm = (angle: number): InkArrowPoint => ({\n x: to.x + headSize * (backX * Math.cos(angle) - backY * Math.sin(angle)),\n y: to.y + headSize * (backX * Math.sin(angle) + backY * Math.cos(angle)),\n });\n\n return { left: arm(HEAD_ANGLE), right: arm(-HEAD_ANGLE) };\n}\n\nexport function inkArrowArmWidth(strokeWidth: number, release: number): number {\n return strokeWidth * release;\n}\n\nexport function inkArrowApex(\n c2: InkArrowPoint,\n to: InkArrowPoint,\n reach: number,\n): InkArrowPoint {\n const dx = to.x - c2.x;\n const dy = to.y - c2.y;\n const length = Math.hypot(dx, dy) || 1;\n return {\n x: to.x + (dx / length) * reach * ARM_OVERSHOOT,\n y: to.y + (dy / length) * reach * ARM_OVERSHOOT,\n };\n}\n\nexport function inkArrowHeadReach(\n headSize: number,\n strokeWidth: number,\n): number {\n return Math.max(headSize, strokeWidth * HEAD_MIN_RATIO);\n}\n\nexport function inkArrowViewport(\n from: InkArrowPoint,\n to: InkArrowPoint,\n curvature: number,\n headSize: number,\n strokeWidth: number,\n grain = 1,\n): { width: number; height: number } {\n const distance = Math.hypot(to.x - from.x, to.y - from.y);\n const margin =\n inkArrowHeadReach(headSize, strokeWidth) +\n Math.abs(curvature) * distance +\n brushReach(strokeWidth, grain);\n return {\n width: Math.max(margin, Math.max(from.x, to.x) + margin),\n height: Math.max(margin, Math.max(from.y, to.y) + margin),\n };\n}\n\nexport interface InkArrowProps {\n from: InkArrowPoint;\n to: InkArrowPoint;\n curvature?: number;\n color?: string;\n strokeWidth?: number;\n pressure?: number;\n release?: number;\n grain?: number;\n delay?: number;\n drawDur?: number;\n headSize?: number;\n headDur?: number;\n seed?: string;\n step?: number;\n}\n\nexport function InkArrow({\n from,\n to,\n curvature = 0.35,\n color = \"#26242c\",\n strokeWidth = 8,\n pressure = 0.2,\n release = 1,\n grain = 1,\n delay = 0,\n drawDur = 36,\n headSize = 24,\n headDur,\n seed = \"arrow\",\n step = DEFAULT_STEP,\n}: InkArrowProps) {\n const frame = useCurrentFrame();\n const progress = steppedRamp(frame, delay, delay + drawDur, { step });\n const { c1, c2 } = inkArrowControls(from, to, curvature, seed);\n const headReach = inkArrowHeadReach(headSize, strokeWidth);\n const head = inkArrowHead(c2, to, headReach);\n const apex = inkArrowApex(c2, to, headReach);\n\n const headFrames = headDur ?? step * 4;\n const headStart = delay + drawDur;\n const headMid = headStart + headFrames / 2;\n const leftArm = steppedRamp(frame, headStart, headMid, { step });\n const rightArm = steppedRamp(frame, headMid, headStart + headFrames, {\n step,\n });\n\n const { width, height } = inkArrowViewport(\n from,\n to,\n curvature,\n headSize,\n strokeWidth,\n grain,\n );\n\n const filterId = brushFilterId(seed, strokeWidth, grain);\n const filter = grain > 0 ? `url(#${filterId})` : undefined;\n\n const armRibbon = (tip: InkArrowPoint, armProgress: number) =>\n brushRibbon(sampleLine(apex, tip, ARM_SAMPLES), {\n strokeWidth: inkArrowArmWidth(strokeWidth, release),\n pressure: 1,\n release: ARM_TAPER,\n progress: armProgress,\n });\n\n return (\n <svg\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n style={{\n display: \"block\",\n overflow: \"visible\",\n opacity: progress > 0 ? 1 : 0,\n }}\n >\n <title>Ink arrow</title>\n <BrushGrain seed={seed} strokeWidth={strokeWidth} grain={grain} />\n <path\n d={brushRibbon(sampleCubic(from, c1, c2, to, SHAFT_SAMPLES), {\n strokeWidth,\n pressure,\n release,\n progress,\n })}\n fill={color}\n opacity={0.85}\n filter={filter}\n />\n {leftArm > 0 ? (\n <path\n d={armRibbon(head.left, leftArm)}\n fill={color}\n opacity={0.85}\n filter={filter}\n />\n ) : null}\n {rightArm > 0 ? (\n <path\n d={armRibbon(head.right, rightArm)}\n fill={color}\n opacity={0.85}\n filter={filter}\n />\n ) : null}\n </svg>\n );\n}\n","type": "registry:component","target": "components/remocn/ink-arrow.tsx"}diff --git a/registry-artifacts/ink-underline.json b/registry-artifacts/ink-underline.jsonindex cc84926b..656e195f 100644--- a/registry-artifacts/ink-underline.json+++ b/registry-artifacts/ink-underline.json@@ -2,13 +2,13 @@"$schema": "https://ui.shadcn.com/schema/registry-item.json","name": "ink-underline","title": "Ink Underline",- "description": "A hand-dragged ink stroke that draws itself across in a few stop-motion poses, with a per-seed wobble.",+ "description": "A hand-dragged brush underline that sweeps itself across in a few stop-motion poses, thinning to a dry tail.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "registry/remocn/ink-underline/index.tsx",- "content": "\"use client\";\n\nimport { useCurrentFrame } from \"remotion\";\nimport { DEFAULT_STEP, hashRange, steppedRamp } from \"@/lib/remocn/stop-motion\";\n\nconst easeOutCubic = (t: number) => 1 - (1 - t) ** 3;\n\nexport interface InkUnderlineProps {\n width: number;\n color?: string;\n thickness?: number;\n delay?: number;\n durationSteps?: number;\n seed?: string;\n step?: number;\n}\n\nexport function InkUnderline({\n width,\n color = \"#6f7f35\",\n thickness = 9,\n delay = 0,\n durationSteps = 5,\n seed = \"ink\",\n step = DEFAULT_STEP,\n}: InkUnderlineProps) {\n const frame = useCurrentFrame();\n const progress = steppedRamp(frame, delay, delay + durationSteps * step, {\n ease: easeOutCubic,\n step,\n });\n const wobble = hashRange(`${seed}:w`, -1.2, 1.2);\n const height = thickness + 4;\n const mid = thickness / 2 + 2;\n\n return (\n <div\n style={{\n width,\n height,\n position: \"relative\",\n opacity: progress > 0 ? 1 : 0,\n }}\n >\n <svg\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n style={{ display: \"block\", overflow: \"visible\" }}\n >\n <path\n d={`M 2 ${mid} C ${width * 0.3} ${mid + wobble}, ${width * 0.7} ${mid - wobble}, ${width - 2} ${mid + wobble * 0.6}`}\n stroke={color}\n strokeWidth={thickness}\n strokeLinecap=\"round\"\n fill=\"none\"\n pathLength={1}\n strokeDasharray={1}\n strokeDashoffset={1 - progress}\n opacity={0.82}\n />\n </svg>\n </div>\n );\n}\n",+ "content": "\"use client\";\n\nimport { useCurrentFrame } from \"remotion\";\nimport {\n BrushGrain,\n type BrushPoint,\n brushFilterId,\n brushReach,\n brushRibbon,\n sampleCubic,\n} from \"@/components/remocn/brush\";\nimport { DEFAULT_STEP, hashRange, steppedRamp } from \"@/lib/remocn/stop-motion\";\n\nconst SAMPLES = 40;\n\nexport function inkUnderlineSpine(\n width: number,\n thickness: number,\n seed: string,\n): BrushPoint[] {\n const wobble = hashRange(`${seed}:w`, -1.2, 1.2);\n const mid = thickness / 2 + 2;\n return sampleCubic(\n { x: 2, y: mid },\n { x: width * 0.3, y: mid + wobble },\n { x: width * 0.7, y: mid - wobble },\n { x: width - 2, y: mid + wobble * 0.6 },\n SAMPLES,\n );\n}\n\nexport interface InkUnderlineProps {\n width: number;\n color?: string;\n thickness?: number;\n pressure?: number;\n release?: number;\n grain?: number;\n delay?: number;\n durationSteps?: number;\n seed?: string;\n step?: number;\n}\n\nexport function InkUnderline({\n width,\n color = \"#6f7f35\",\n thickness = 9,\n pressure = 1,\n release = 0.15,\n grain = 1,\n delay = 0,\n durationSteps = 5,\n seed = \"ink\",\n step = DEFAULT_STEP,\n}: InkUnderlineProps) {\n const frame = useCurrentFrame();\n const progress = steppedRamp(frame, delay, delay + durationSteps * step, {\n step,\n });\n\n const reach = brushReach(thickness, grain);\n const height = thickness + 4;\n const d = brushRibbon(inkUnderlineSpine(width, thickness, seed), {\n strokeWidth: thickness,\n pressure,\n release,\n progress,\n });\n\n return (\n <div\n style={{\n width,\n height,\n position: \"relative\",\n opacity: progress > 0 ? 1 : 0,\n }}\n >\n <svg\n width={width + reach * 2}\n height={height + reach * 2}\n viewBox={`${-reach} ${-reach} ${width + reach * 2} ${height + reach * 2}`}\n style={{\n position: \"absolute\",\n left: -reach,\n top: -reach,\n display: \"block\",\n overflow: \"visible\",\n }}\n >\n <title>Ink underline</title>\n <BrushGrain seed={seed} strokeWidth={thickness} grain={grain} />\n <path\n d={d}\n fill={color}\n opacity={0.85}\n filter={\n grain > 0\n ? `url(#${brushFilterId(seed, thickness, grain)})`\n : undefined\n }\n />\n </svg>\n </div>\n );\n}\n","type": "registry:component","target": "components/remocn/ink-underline.tsx"}diff --git a/registry-artifacts/registry.json b/registry-artifacts/registry.jsonindex 9914f6e2..171553f4 100644--- a/registry-artifacts/registry.json+++ b/registry-artifacts/registry.json@@ -1301,9 +1301,9 @@{"name": "ink-underline","title": "Ink Underline",- "description": "A hand-dragged ink stroke that draws itself across in a few stop-motion poses, with a per-seed wobble.",+ "description": "A hand-dragged brush underline that sweeps itself across in a few stop-motion poses, thinning to a dry tail.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "registry/remocn/ink-underline/index.tsx",@@ -1331,9 +1331,9 @@{"name": "ink-arrow","title": "Ink Arrow",- "description": "A hand-drawn arrow that draws itself from one point to another in stop-motion poses, with the head popping on the final pose.",+ "description": "A hand-drawn brush arrow that sweeps itself from one point to another, thickening into the head that pops on the final poses.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "registry/remocn/ink-arrow/index.tsx",@@ -1373,12 +1373,26 @@],"type": "registry:component"},+ {+ "name": "brush",+ "title": "Brush",+ "description": "Variable-width brush ribbons for Remotion. Pressure taper, grain displacement, and spine samplers shared by the ink marks.",+ "registryDependencies": ["@remocn/stop-motion"],+ "files": [+ {+ "path": "registry/remocn/brush/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/brush.tsx"+ }+ ],+ "type": "registry:component"+ },{"name": "scribble-circle","title": "Scribble Circle","description": "A brush circle swept around a region of the frame, opening thin and closing thick, with grain breaking up the dry opening.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "registry/remocn/scribble-circle/index.tsx",diff --git a/registry-artifacts/scribble-circle.json b/registry-artifacts/scribble-circle.jsonindex ba99d5ba..25b5bd0b 100644--- a/registry-artifacts/scribble-circle.json+++ b/registry-artifacts/scribble-circle.json@@ -4,11 +4,11 @@"title": "Scribble Circle","description": "A brush circle swept around a region of the frame, opening thin and closing thick, with grain breaking up the dry opening.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "registry/remocn/scribble-circle/index.tsx",- "content": "\"use client\";\n\nimport { useCurrentFrame } from \"remotion\";\nimport {\n DEFAULT_STEP,\n hash01,\n hashRange,\n steppedRamp,\n} from \"@/lib/remocn/stop-motion\";\n\nconst SAMPLES_PER_LAP = 48;\nconst NOISE = 0.035;\nconst CENTRE = 0.02;\nconst GRAIN_RATIO = 0.5;\n\nexport type ScribblePoint = { x: number; y: number };\n\nexport type ScribbleCircleGeometry = {\n width: number;\n height: number;\n strokeWidth: number;\n laps?: number;\n pressure?: number;\n grain?: number;\n seed?: string;\n points?: number;\n progress?: number;\n};\n\nexport function scribbleCircleCentre(\n width: number,\n height: number,\n seed = \"scribble\",\n): ScribblePoint {\n return {\n x: width / 2 + hashRange(`${seed}:cx`, -CENTRE, CENTRE) * width,\n y: height / 2 + hashRange(`${seed}:cy`, -CENTRE, CENTRE) * height,\n };\n}\n\nexport function scribbleCirclePoints(args: {\n width: number;\n height: number;\n laps?: number;\n seed?: string;\n points?: number;\n}): ScribblePoint[] {\n const laps = args.laps ?? 1.15;\n const seed = args.seed ?? \"scribble\";\n const points = args.points ?? SAMPLES_PER_LAP;\n\n const count = Math.max(2, Math.ceil(laps * points));\n const rx = args.width / 2;\n const ry = args.height / 2;\n const { x: cx, y: cy } = scribbleCircleCentre(args.width, args.height, seed);\n\n return Array.from({ length: count }, (_, i) => {\n const angle = laps * Math.PI * 2 * (i / (count - 1));\n const scale = 1 + hashRange(`${seed}:r${i}`, -NOISE, NOISE);\n return {\n x: cx + rx * scale * Math.cos(angle),\n y: cy + ry * scale * Math.sin(angle),\n };\n });\n}\n\nexport function scribbleCircleHalfWidth(\n strokeWidth: number,\n pressure: number,\n t: number,\n): number {\n return (strokeWidth / 2) * (pressure + (1 - pressure) * t);\n}\n\nexport function scribbleCircleGrainScale(\n strokeWidth: number,\n grain: number,\n): number {\n return strokeWidth * GRAIN_RATIO * grain;\n}\n\nconst normalAt = (points: ScribblePoint[], i: number): ScribblePoint => {\n const before = points[i - 1] ?? points[i];\n const after = points[i + 1] ?? points[i];\n const tx = after.x - before.x;\n const ty = after.y - before.y;\n const length = Math.hypot(tx, ty) || 1;\n return { x: -ty / length, y: tx / length };\n};\n\nconst curveSegments = (points: ScribblePoint[]): string =>\n points\n .slice(0, -1)\n .map((p1, i) => {\n const p0 = points[i - 1] ?? p1;\n const p2 = points[i + 1];\n const p3 = points[i + 2] ?? p2;\n return `C ${p1.x + (p2.x - p0.x) / 6} ${p1.y + (p2.y - p0.y) / 6}, ${p2.x - (p3.x - p1.x) / 6} ${p2.y - (p3.y - p1.y) / 6}, ${p2.x} ${p2.y}`;\n })\n .join(\" \");\n\nexport function scribbleCirclePath(args: ScribbleCircleGeometry): {\n d: string;\n viewBox: string;\n marginX: number;\n marginY: number;\n} {\n const pressure = args.pressure ?? 0.2;\n const grain = args.grain ?? 1;\n const progress = args.progress ?? 1;\n const spine = scribbleCirclePoints(args);\n const drawn = Math.max(2, Math.round(progress * (spine.length - 1)) + 1);\n\n const left: ScribblePoint[] = [];\n const right: ScribblePoint[] = [];\n for (let i = 0; i < drawn; i++) {\n const half = scribbleCircleHalfWidth(\n args.strokeWidth,\n pressure,\n i / (spine.length - 1),\n );\n const normal = normalAt(spine, i);\n left.push({\n x: spine[i].x + normal.x * half,\n y: spine[i].y + normal.y * half,\n });\n right.push({\n x: spine[i].x - normal.x * half,\n y: spine[i].y - normal.y * half,\n });\n }\n const back = right.slice().reverse();\n\n const reach =\n args.strokeWidth / 2 +\n scribbleCircleGrainScale(args.strokeWidth, grain) / 2;\n const marginX = reach + (args.width / 2) * NOISE + args.width * CENTRE;\n const marginY = reach + (args.height / 2) * NOISE + args.height * CENTRE;\n\n return {\n d: `M ${left[0].x} ${left[0].y} ${curveSegments(left)} L ${back[0].x} ${back[0].y} ${curveSegments(back)} Z`,\n viewBox: `${-marginX} ${-marginY} ${args.width + marginX * 2} ${args.height + marginY * 2}`,\n marginX,\n marginY,\n };\n}\n\nexport function scribbleCircleProgress(\n frame: number,\n options?: { delay?: number; durationSteps?: number; step?: number },\n): number {\n const delay = options?.delay ?? 0;\n const durationSteps = options?.durationSteps ?? 10;\n const step = options?.step ?? DEFAULT_STEP;\n return steppedRamp(frame, delay, delay + durationSteps * step, { step });\n}\n\nexport interface ScribbleCircleProps {\n width: number;\n height: number;\n color?: string;\n strokeWidth?: number;\n pressure?: number;\n grain?: number;\n delay?: number;\n durationSteps?: number;\n laps?: number;\n seed?: string;\n step?: number;\n}\n\nexport function ScribbleCircle({\n width,\n height,\n color = \"#6f7f35\",\n strokeWidth = 14,\n pressure = 0.2,\n grain = 1,\n delay = 0,\n durationSteps = 10,\n laps = 1.15,\n seed = \"scribble\",\n step = DEFAULT_STEP,\n}: ScribbleCircleProps) {\n const frame = useCurrentFrame();\n const progress = scribbleCircleProgress(frame, {\n delay,\n durationSteps,\n step,\n });\n const { d, viewBox, marginX, marginY } = scribbleCirclePath({\n width,\n height,\n strokeWidth,\n laps,\n pressure,\n grain,\n seed,\n progress,\n });\n\n const grainScale = scribbleCircleGrainScale(strokeWidth, grain);\n const filterId = `scribble-grain-${Math.floor(hash01(seed) * 1e9)}`;\n\n return (\n <div\n style={{\n position: \"relative\",\n width,\n height,\n opacity: progress > 0 ? 1 : 0,\n }}\n >\n <svg\n width={width + marginX * 2}\n height={height + marginY * 2}\n viewBox={viewBox}\n style={{\n position: \"absolute\",\n left: -marginX,\n top: -marginY,\n display: \"block\",\n overflow: \"visible\",\n }}\n >\n <title>Scribbled circle</title>\n <defs>\n <filter\n id={filterId}\n x=\"-30%\"\n y=\"-30%\"\n width=\"160%\"\n height=\"160%\"\n filterUnits=\"objectBoundingBox\"\n >\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.7\"\n numOctaves={3}\n seed={Math.floor(hash01(`${seed}:grain`) * 1000)}\n result=\"grain\"\n />\n <feDisplacementMap\n in=\"SourceGraphic\"\n in2=\"grain\"\n scale={grainScale}\n xChannelSelector=\"R\"\n yChannelSelector=\"G\"\n />\n </filter>\n </defs>\n <path\n d={d}\n fill={color}\n opacity={0.85}\n filter={grain > 0 ? `url(#${filterId})` : undefined}\n />\n </svg>\n </div>\n );\n}\n",+ "content": "\"use client\";\n\nimport { useCurrentFrame } from \"remotion\";\nimport {\n BrushGrain,\n type BrushPoint,\n brushFilterId,\n brushReach,\n brushRibbon,\n} from \"@/components/remocn/brush\";\nimport { DEFAULT_STEP, hashRange, steppedRamp } from \"@/lib/remocn/stop-motion\";\n\nconst SAMPLES_PER_LAP = 48;\nconst NOISE = 0.035;\nconst CENTRE = 0.02;\n\nexport type ScribbleCircleGeometry = {\n width: number;\n height: number;\n strokeWidth: number;\n laps?: number;\n pressure?: number;\n release?: number;\n grain?: number;\n seed?: string;\n points?: number;\n progress?: number;\n};\n\nexport function scribbleCircleCentre(\n width: number,\n height: number,\n seed = \"scribble\",\n): BrushPoint {\n return {\n x: width / 2 + hashRange(`${seed}:cx`, -CENTRE, CENTRE) * width,\n y: height / 2 + hashRange(`${seed}:cy`, -CENTRE, CENTRE) * height,\n };\n}\n\nexport function scribbleCirclePoints(args: {\n width: number;\n height: number;\n laps?: number;\n seed?: string;\n points?: number;\n}): BrushPoint[] {\n const laps = args.laps ?? 1.15;\n const seed = args.seed ?? \"scribble\";\n const points = args.points ?? SAMPLES_PER_LAP;\n\n const count = Math.max(2, Math.ceil(laps * points));\n const rx = args.width / 2;\n const ry = args.height / 2;\n const { x: cx, y: cy } = scribbleCircleCentre(args.width, args.height, seed);\n\n return Array.from({ length: count }, (_, i) => {\n const angle = laps * Math.PI * 2 * (i / (count - 1));\n const scale = 1 + hashRange(`${seed}:r${i}`, -NOISE, NOISE);\n return {\n x: cx + rx * scale * Math.cos(angle),\n y: cy + ry * scale * Math.sin(angle),\n };\n });\n}\n\nexport function scribbleCirclePath(args: ScribbleCircleGeometry): {\n d: string;\n viewBox: string;\n marginX: number;\n marginY: number;\n} {\n const grain = args.grain ?? 1;\n const reach = brushReach(args.strokeWidth, grain);\n const marginX = reach + (args.width / 2) * NOISE + args.width * CENTRE;\n const marginY = reach + (args.height / 2) * NOISE + args.height * CENTRE;\n\n return {\n d: brushRibbon(scribbleCirclePoints(args), {\n strokeWidth: args.strokeWidth,\n pressure: args.pressure,\n release: args.release,\n progress: args.progress,\n }),\n viewBox: `${-marginX} ${-marginY} ${args.width + marginX * 2} ${args.height + marginY * 2}`,\n marginX,\n marginY,\n };\n}\n\nexport function scribbleCircleProgress(\n frame: number,\n options?: { delay?: number; durationSteps?: number; step?: number },\n): number {\n const delay = options?.delay ?? 0;\n const durationSteps = options?.durationSteps ?? 10;\n const step = options?.step ?? DEFAULT_STEP;\n return steppedRamp(frame, delay, delay + durationSteps * step, { step });\n}\n\nexport interface ScribbleCircleProps {\n width: number;\n height: number;\n color?: string;\n strokeWidth?: number;\n pressure?: number;\n release?: number;\n grain?: number;\n delay?: number;\n durationSteps?: number;\n laps?: number;\n seed?: string;\n step?: number;\n}\n\nexport function ScribbleCircle({\n width,\n height,\n color = \"#6f7f35\",\n strokeWidth = 14,\n pressure = 0.2,\n release = 1,\n grain = 1,\n delay = 0,\n durationSteps = 10,\n laps = 1.15,\n seed = \"scribble\",\n step = DEFAULT_STEP,\n}: ScribbleCircleProps) {\n const frame = useCurrentFrame();\n const progress = scribbleCircleProgress(frame, {\n delay,\n durationSteps,\n step,\n });\n const { d, viewBox, marginX, marginY } = scribbleCirclePath({\n width,\n height,\n strokeWidth,\n laps,\n pressure,\n release,\n grain,\n seed,\n progress,\n });\n\n return (\n <div\n style={{\n position: \"relative\",\n width,\n height,\n opacity: progress > 0 ? 1 : 0,\n }}\n >\n <svg\n width={width + marginX * 2}\n height={height + marginY * 2}\n viewBox={viewBox}\n style={{\n position: \"absolute\",\n left: -marginX,\n top: -marginY,\n display: \"block\",\n overflow: \"visible\",\n }}\n >\n <title>Scribbled circle</title>\n <BrushGrain seed={seed} strokeWidth={strokeWidth} grain={grain} />\n <path\n d={d}\n fill={color}\n opacity={0.85}\n filter={\n grain > 0\n ? `url(#${brushFilterId(seed, strokeWidth, grain)})`\n : undefined\n }\n />\n </svg>\n </div>\n );\n}\n","type": "registry:component","target": "components/remocn/scribble-circle.tsx"}diff --git a/registry/remocn/brush/__tests__/brush.test.ts b/registry/remocn/brush/__tests__/brush.test.tsnew file mode 100644index 00000000..6e41dece--- /dev/null+++ b/registry/remocn/brush/__tests__/brush.test.ts@@ -0,0 +1,231 @@+import { describe, expect, it } from "bun:test";++import {+ brushFilterId,+ brushGrainScale,+ brushHalfWidth,+ brushReach,+ brushRibbon,+ sampleCubic,+ sampleLine,+} from "../index";++const STROKE = 14;++const numbersIn = (d: string) =>+ d.match(/-?\d+(\.\d+)?(e-?\d+)?/g)?.map(Number) ?? [];++const straightSpine = sampleLine({ x: 0, y: 50 }, { x: 200, y: 50 }, 20);++describe("brushHalfWidth", () => {+ it("opens at pressure and closes at release", () => {+ expect(+ brushHalfWidth({ strokeWidth: STROKE, pressure: 0.2 }, 0),+ ).toBeCloseTo(1.4);+ expect(+ brushHalfWidth({ strokeWidth: STROKE, pressure: 0.2 }, 1),+ ).toBeCloseTo(7);+ });++ it("tapers the other way when release is below pressure", () => {+ const taper = { strokeWidth: STROKE, pressure: 1, release: 0.15 };+ expect(brushHalfWidth(taper, 0)).toBeCloseTo(7);+ expect(brushHalfWidth(taper, 1)).toBeCloseTo(1.05);+ expect(brushHalfWidth(taper, 0)).toBeGreaterThan(brushHalfWidth(taper, 1));+ });++ it("is monotonic in both directions", () => {+ const thickening = { strokeWidth: STROKE, pressure: 0.2, release: 1 };+ const thinning = { strokeWidth: STROKE, pressure: 1, release: 0.2 };+ for (let i = 1; i <= 20; i++) {+ expect(brushHalfWidth(thickening, i / 20)).toBeGreaterThan(+ brushHalfWidth(thickening, (i - 1) / 20),+ );+ expect(brushHalfWidth(thinning, i / 20)).toBeLessThan(+ brushHalfWidth(thinning, (i - 1) / 20),+ );+ }+ });++ it("is uniform when pressure equals release", () => {+ for (const t of [0, 0.4, 1]) {+ expect(+ brushHalfWidth({ strokeWidth: STROKE, pressure: 1, release: 1 }, t),+ ).toBeCloseTo(STROKE / 2);+ }+ });++ it("never exceeds half the stroke width inside the control range", () => {+ for (let p = 0.05; p <= 1.0001; p += 0.05) {+ for (let r = 0.05; r <= 1.0001; r += 0.05) {+ for (const t of [0, 0.5, 1]) {+ const half = brushHalfWidth(+ { strokeWidth: STROKE, pressure: p, release: r },+ t,+ );+ expect(half).toBeGreaterThan(0);+ expect(half).toBeLessThanOrEqual(STROKE / 2 + 1e-9);+ }+ }+ }+ });+});++describe("brushReach", () => {+ it("covers half the ribbon plus half the grain displacement", () => {+ expect(brushReach(STROKE, 1)).toBeCloseTo(+ STROKE / 2 + brushGrainScale(STROKE, 1) / 2,+ );+ });++ it("collapses to half the ribbon when grain is off", () => {+ expect(brushReach(STROKE, 0)).toBeCloseTo(STROKE / 2);+ });++ it("grows with grain", () => {+ expect(brushReach(STROKE, 2)).toBeGreaterThan(brushReach(STROKE, 1));+ });++ it("leaves the thin end narrower than the displacement, so it breaks up", () => {+ const opening = brushHalfWidth({ strokeWidth: STROKE, pressure: 0.2 }, 0);+ expect(opening * 2).toBeLessThan(brushGrainScale(STROKE, 1));+ });+});++describe("brushFilterId", () => {+ it("is stable for the same brush", () => {+ expect(brushFilterId("ink", 8, 1)).toBe(brushFilterId("ink", 8, 1));+ });++ it("separates brushes that share a seed but differ in weight or grain", () => {+ expect(brushFilterId("ink", 8, 1)).not.toBe(brushFilterId("ink", 14, 1));+ expect(brushFilterId("ink", 8, 1)).not.toBe(brushFilterId("ink", 8, 2));+ });++ it("is a valid css identifier", () => {+ expect(brushFilterId("ink", 8, 1)).toMatch(/^[a-zA-Z][\w-]*$/);+ });+});++describe("sampleCubic", () => {+ it("hits both endpoints exactly", () => {+ const from = { x: 0, y: 0 };+ const to = { x: 100, y: 40 };+ const curve = sampleCubic(+ from,+ { x: 30, y: 60 },+ { x: 70, y: -20 },+ to,+ 24,+ );+ expect(curve).toHaveLength(24);+ expect(curve[0]).toEqual(from);+ expect(curve.at(-1)?.x).toBeCloseTo(to.x, 9);+ expect(curve.at(-1)?.y).toBeCloseTo(to.y, 9);+ });++ it("reduces to the straight segment when controls sit on it", () => {+ const curve = sampleCubic(+ { x: 0, y: 0 },+ { x: 25, y: 0 },+ { x: 75, y: 0 },+ { x: 100, y: 0 },+ 9,+ );+ for (const point of curve) {+ expect(point.y).toBeCloseTo(0, 9);+ }+ expect(curve[4].x).toBeCloseTo(50, 9);+ });++ it("never returns fewer than two points", () => {+ expect(+ sampleCubic(+ { x: 0, y: 0 },+ { x: 1, y: 1 },+ { x: 2, y: 2 },+ { x: 3, y: 3 },+ 0,+ ),+ ).toHaveLength(2);+ });+});++describe("sampleLine", () => {+ it("walks evenly from end to end", () => {+ const line = sampleLine({ x: 0, y: 0 }, { x: 10, y: 0 }, 11);+ expect(line[0]).toEqual({ x: 0, y: 0 });+ expect(line.at(-1)).toEqual({ x: 10, y: 0 });+ expect(line[5].x).toBeCloseTo(5, 9);+ });+});++describe("brushRibbon", () => {+ it("is a single closed subpath, not a stroked polyline", () => {+ const d = brushRibbon(straightSpine, { strokeWidth: STROKE });+ expect(d.match(/M/g)).toHaveLength(1);+ expect(d.match(/Z/g)).toHaveLength(1);+ expect(d.trimEnd().endsWith("Z")).toBe(true);+ });++ it("offsets the two sides by the taper, thin end first", () => {+ const d = brushRibbon(straightSpine, {+ strokeWidth: STROKE,+ pressure: 0.2,+ release: 1,+ });+ const ys = numbersIn(d).filter((_, i) => i % 2 === 1);+ const spread = Math.max(...ys) - Math.min(...ys);+ expect(spread).toBeCloseTo(STROKE, 0);+ });++ it("widens with strokeWidth", () => {+ const spread = (strokeWidth: number) => {+ const ys = numbersIn(+ brushRibbon(straightSpine, { strokeWidth, pressure: 1, release: 1 }),+ ).filter((_, i) => i % 2 === 1);+ return Math.max(...ys) - Math.min(...ys);+ };+ expect(spread(20)).toBeGreaterThan(spread(6));+ expect(spread(20)).toBeCloseTo(20, 6);+ });++ it("grows as progress advances", () => {+ let previous = 0;+ for (const progress of [0.1, 0.4, 0.8, 1]) {+ const length = numbersIn(+ brushRibbon(straightSpine, { strokeWidth: STROKE, progress }),+ ).length;+ expect(length).toBeGreaterThan(previous);+ previous = length;+ }+ });++ it("anchors the taper to the whole spine, not the drawn part", () => {+ const half = brushRibbon(straightSpine, {+ strokeWidth: STROKE,+ progress: 0.5,+ });+ const full = brushRibbon(straightSpine, { strokeWidth: STROKE });+ expect(full.startsWith(half.slice(0, 30))).toBe(true);+ });++ it("stays finite and well formed at zero progress", () => {+ const d = brushRibbon(straightSpine, { strokeWidth: STROKE, progress: 0 });+ expect(d.match(/M/g)).toHaveLength(1);+ expect(numbersIn(d).every(Number.isFinite)).toBe(true);+ });++ it("survives a spine with repeated points", () => {+ const stalled = [+ { x: 0, y: 0 },+ { x: 0, y: 0 },+ { x: 10, y: 0 },+ ];+ expect(+ numbersIn(brushRibbon(stalled, { strokeWidth: STROKE })).every(+ Number.isFinite,+ ),+ ).toBe(true);+ });+});diff --git a/registry/remocn/brush/index.tsx b/registry/remocn/brush/index.tsxnew file mode 100644index 00000000..5eb4241d--- /dev/null+++ b/registry/remocn/brush/index.tsx@@ -0,0 +1,157 @@+"use client";++import { hash01 } from "@/lib/remocn/stop-motion";++const GRAIN_RATIO = 0.5;+const GRAIN_FREQUENCY = 0.7;+const GRAIN_OCTAVES = 3;++export type BrushPoint = { x: number; y: number };++export type BrushTaper = {+ strokeWidth: number;+ pressure?: number;+ release?: number;+};++export function brushHalfWidth(taper: BrushTaper, t: number): number {+ const pressure = taper.pressure ?? 0.2;+ const release = taper.release ?? 1;+ return (taper.strokeWidth / 2) * (pressure + (release - pressure) * t);+}++export function brushGrainScale(strokeWidth: number, grain: number): number {+ return strokeWidth * GRAIN_RATIO * grain;+}++export function brushReach(strokeWidth: number, grain: number): number {+ return strokeWidth / 2 + brushGrainScale(strokeWidth, grain) / 2;+}++export function brushFilterId(+ seed: string,+ strokeWidth: number,+ grain: number,+): string {+ return `remocn-brush-${Math.floor(hash01(`${seed}:${strokeWidth}:${grain}`) * 1e9)}`;+}++export function sampleCubic(+ from: BrushPoint,+ c1: BrushPoint,+ c2: BrushPoint,+ to: BrushPoint,+ points = 32,+): BrushPoint[] {+ const count = Math.max(2, points);+ return Array.from({ length: count }, (_, i) => {+ const t = i / (count - 1);+ const u = 1 - t;+ const a = u * u * u;+ const b = 3 * u * u * t;+ const c = 3 * u * t * t;+ const d = t * t * t;+ return {+ x: a * from.x + b * c1.x + c * c2.x + d * to.x,+ y: a * from.y + b * c1.y + c * c2.y + d * to.y,+ };+ });+}++export function sampleLine(+ from: BrushPoint,+ to: BrushPoint,+ points = 8,+): BrushPoint[] {+ const count = Math.max(2, points);+ return Array.from({ length: count }, (_, i) => {+ const t = i / (count - 1);+ return {+ x: from.x + (to.x - from.x) * t,+ y: from.y + (to.y - from.y) * t,+ };+ });+}++const normalAt = (points: BrushPoint[], i: number): BrushPoint => {+ const before = points[i - 1] ?? points[i];+ const after = points[i + 1] ?? points[i];+ const tx = after.x - before.x;+ const ty = after.y - before.y;+ const length = Math.hypot(tx, ty) || 1;+ return { x: -ty / length, y: tx / length };+};++const curveSegments = (points: BrushPoint[]): string =>+ points+ .slice(0, -1)+ .map((p1, i) => {+ const p0 = points[i - 1] ?? p1;+ const p2 = points[i + 1];+ const p3 = points[i + 2] ?? p2;+ return `C ${p1.x + (p2.x - p0.x) / 6} ${p1.y + (p2.y - p0.y) / 6}, ${p2.x - (p3.x - p1.x) / 6} ${p2.y - (p3.y - p1.y) / 6}, ${p2.x} ${p2.y}`;+ })+ .join(" ");++export function brushRibbon(+ spine: BrushPoint[],+ options: BrushTaper & { progress?: number },+): string {+ const progress = options.progress ?? 1;+ const drawn = Math.max(2, Math.round(progress * (spine.length - 1)) + 1);++ const left: BrushPoint[] = [];+ const right: BrushPoint[] = [];+ for (let i = 0; i < drawn; i++) {+ const half = brushHalfWidth(options, i / (spine.length - 1));+ const normal = normalAt(spine, i);+ left.push({+ x: spine[i].x + normal.x * half,+ y: spine[i].y + normal.y * half,+ });+ right.push({+ x: spine[i].x - normal.x * half,+ y: spine[i].y - normal.y * half,+ });+ }+ const back = right.slice().reverse();++ return `M ${left[0].x} ${left[0].y} ${curveSegments(left)} L ${back[0].x} ${back[0].y} ${curveSegments(back)} Z`;+}++export function BrushGrain({+ seed,+ strokeWidth,+ grain,+}: {+ seed: string;+ strokeWidth: number;+ grain: number;+}) {+ return (+ <defs>+ <filter+ id={brushFilterId(seed, strokeWidth, grain)}+ x="-30%"+ y="-30%"+ width="160%"+ height="160%"+ >+ <feTurbulence+ type="fractalNoise"+ baseFrequency={GRAIN_FREQUENCY}+ numOctaves={GRAIN_OCTAVES}+ seed={Math.floor(hash01(`${seed}:grain`) * 1000)}+ result="brushGrain"+ />+ <feDisplacementMap+ in="SourceGraphic"+ in2="brushGrain"+ scale={brushGrainScale(strokeWidth, grain)}+ xChannelSelector="R"+ yChannelSelector="G"+ />+ </filter>+ </defs>+ );+}diff --git a/registry/remocn/ink-arrow/__tests__/ink-arrow.test.ts b/registry/remocn/ink-arrow/__tests__/ink-arrow.test.tsindex 6a06b5f9..f1f4eac8 100644--- a/registry/remocn/ink-arrow/__tests__/ink-arrow.test.ts+++ b/registry/remocn/ink-arrow/__tests__/ink-arrow.test.ts@@ -1,6 +1,31 @@import { describe, expect, it } from "bun:test";-import { inkArrowControls, inkArrowHead, inkArrowViewport } from "../index";+import { brushHalfWidth, brushReach } from "@/components/remocn/brush";+import { inkArrowConfig } from "../config";+import {+ inkArrowApex,+ inkArrowArmWidth,+ inkArrowControls,+ inkArrowHead,+ inkArrowHeadReach,+ inkArrowViewport,+} from "../index";++const numberControl = (name: string) => {+ const control = inkArrowConfig.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 FROM = { x: 0, y: 0 };const TO = { x: 100, y: 0 };@@ -88,9 +113,129 @@ describe("inkArrowViewport", () => {expect(height).toBeGreaterThan(200);});- it("leaves room for the bow, the head and the pen width", () => {- const { width } = inkArrowViewport(FROM, TO, 0.5, 24, 3);- expect(width).toBeCloseTo(100 + 24 + 50 + 3, 6);+ it("leaves room for the bow, the head and the brush reach", () => {+ const { width } = inkArrowViewport(FROM, TO, 0.5, 24, 8);+ expect(width).toBeCloseTo(100 + 24 + 50 + brushReach(8, 1), 6);+ });++ it("widens as grain grows, since the displacement pushes past the ribbon", () => {+ const clean = inkArrowViewport(FROM, TO, 0.5, 24, 8, 0).width;+ const rough = inkArrowViewport(FROM, TO, 0.5, 24, 8, 2).width;+ expect(rough).toBeGreaterThan(clean);+ expect(clean).toBeCloseTo(100 + 24 + 50 + 4, 6);+ });+});++describe("inkArrowHeadReach", () => {+ it("leaves headSize alone while the brush stays thin", () => {+ expect(inkArrowHeadReach(24, 8)).toBe(24);+ expect(inkArrowHeadReach(48, 8)).toBe(48);+ });++ it("grows the head once the brush would swallow it", () => {+ expect(inkArrowHeadReach(24, 24)).toBeCloseTo(62.4);+ expect(inkArrowHeadReach(24, 24)).toBeGreaterThan(inkArrowHeadReach(24, 8));+ });++ it("keeps the arms clear of the shaft across the whole control matrix", () => {+ for (const headSize of controlValues("headSize")) {+ for (const strokeWidth of controlValues("strokeWidth")) {+ const reach = inkArrowHeadReach(headSize, strokeWidth);+ expect(reach).toBeGreaterThan(strokeWidth / 2);+ expect(reach).toBeGreaterThanOrEqual(strokeWidth * 2);+ }+ }+ });++ it("never shrinks the head below what the user asked for", () => {+ for (const headSize of controlValues("headSize")) {+ for (const strokeWidth of controlValues("strokeWidth")) {+ expect(inkArrowHeadReach(headSize, strokeWidth)).toBeGreaterThanOrEqual(+ headSize,+ );+ }+ }+ });++ it("is what the viewport reserves, so a grown head is never clipped", () => {+ const wide = inkArrowViewport(FROM, TO, 0, 24, 24, 0).width;+ expect(wide).toBeCloseTo(+ 100 + inkArrowHeadReach(24, 24) + brushReach(24, 0),+ 6,+ );+ });+});++describe("inkArrowApex", () => {+ const c2 = { x: 60, y: 0 };++ it("sits ahead of the tip, so the two arms cross instead of meeting in a blob", () => {+ const apex = inkArrowApex(c2, TO, 24);+ expect(apex.x).toBeGreaterThan(TO.x);+ expect(apex.y).toBeCloseTo(TO.y, 9);+ });++ it("overshoots by a fraction of the head reach", () => {+ expect(Math.hypot(inkArrowApex(c2, TO, 50).x - TO.x, 0)).toBeCloseTo(8, 6);+ expect(Math.hypot(inkArrowApex(c2, TO, 25).x - TO.x, 0)).toBeCloseTo(4, 6);+ });++ it("follows the end tangent, not the axis", () => {+ const apex = inkArrowApex({ x: 100, y: 60 }, TO, 40);+ expect(apex.y).toBeLessThan(TO.y);+ });++ it("survives a degenerate tangent", () => {+ const apex = inkArrowApex(TO, TO, 24);+ expect(Number.isFinite(apex.x)).toBe(true);+ expect(Number.isFinite(apex.y)).toBe(true);+ });+});++describe("inkArrowArmWidth", () => {+ it("matches the shaft's own width where the shaft ends", () => {+ for (const strokeWidth of controlValues("strokeWidth")) {+ for (const release of [0.2, 0.5, 1]) {+ const shaftEnd =+ 2 * brushHalfWidth({ strokeWidth, pressure: 0.2, release }, 1);+ expect(inkArrowArmWidth(strokeWidth, release)).toBeCloseTo(shaftEnd, 9);+ }+ }+ });++ it("follows release, so a shaft that lifts off thin gets a thin head", () => {+ expect(inkArrowArmWidth(24, 1)).toBe(24);+ expect(inkArrowArmWidth(24, 0.5)).toBe(12);+ expect(inkArrowArmWidth(24, 0.5)).toBeLessThan(inkArrowArmWidth(24, 1));+ });++ it("is independent of pressure, which only shapes the opening", () => {+ const end = (pressure: number) =>+ 2 * brushHalfWidth({ strokeWidth: 16, pressure, release: 1 }, 1);+ expect(end(0.05)).toBeCloseTo(inkArrowArmWidth(16, 1), 9);+ expect(end(1)).toBeCloseTo(inkArrowArmWidth(16, 1), 9);+ });+});++describe("the head reads as a V at every brush width", () => {+ it("spreads the arms wider than the shaft is thick", () => {+ for (const headSize of controlValues("headSize")) {+ for (const strokeWidth of controlValues("strokeWidth")) {+ const reach = inkArrowHeadReach(headSize, strokeWidth);+ const { left, right } = inkArrowHead({ x: 60, y: 0 }, TO, reach);+ const span = Math.hypot(left.x - right.x, left.y - right.y);+ expect(span).toBeGreaterThan(strokeWidth);+ }+ }+ });++ it("keeps the arm tips behind the apex so the V never inverts", () => {+ const reach = inkArrowHeadReach(24, 24);+ const apex = inkArrowApex({ x: 60, y: 0 }, TO, reach);+ const { left, right } = inkArrowHead({ x: 60, y: 0 }, TO, reach);+ for (const arm of [left, right]) {+ expect(arm.x).toBeLessThan(apex.x);+ }});});diff --git a/registry/remocn/ink-arrow/config.ts b/registry/remocn/ink-arrow/config.tsindex 42804234..4e725c06 100644--- a/registry/remocn/ink-arrow/config.ts+++ b/registry/remocn/ink-arrow/config.ts@@ -15,11 +15,35 @@ export const inkArrowConfig: ComponentConfig = {},strokeWidth: {type: "number",- default: 3,- min: 1,- max: 10,+ default: 8,+ min: 2,+ max: 24,step: 1,- label: "Stroke width",+ label: "Brush width",+ },+ pressure: {+ type: "number",+ default: 0.2,+ min: 0.05,+ max: 1,+ step: 0.05,+ label: "Opening pressure",+ },+ release: {+ type: "number",+ default: 1,+ min: 0.05,+ max: 1,+ step: 0.05,+ label: "Closing pressure",+ },+ grain: {+ type: "number",+ default: 1,+ min: 0,+ max: 2,+ step: 0.1,+ label: "Grain",},headSize: {type: "number",diff --git a/registry/remocn/ink-arrow/index.tsx b/registry/remocn/ink-arrow/index.tsxindex cf187b01..4942f42c 100644--- a/registry/remocn/ink-arrow/index.tsx+++ b/registry/remocn/ink-arrow/index.tsx@@ -1,13 +1,25 @@"use client";import { useCurrentFrame } from "remotion";+import {+ BrushGrain,+ type BrushPoint,+ brushFilterId,+ brushReach,+ brushRibbon,+ sampleCubic,+ sampleLine,+} from "@/components/remocn/brush";import { DEFAULT_STEP, hashRange, steppedRamp } from "@/lib/remocn/stop-motion";-const easeOutCubic = (t: number) => 1 - (1 - t) ** 3;+const HEAD_ANGLE = 0.72;+const SHAFT_SAMPLES = 40;+const ARM_SAMPLES = 10;+const ARM_TAPER = 0.6;+const ARM_OVERSHOOT = 0.16;+const HEAD_MIN_RATIO = 2.6;-const HEAD_ANGLE = 0.6;--export type InkArrowPoint = { x: number; y: number };+export type InkArrowPoint = BrushPoint;export function inkArrowControls(from: InkArrowPoint,@@ -58,15 +70,44 @@ export function inkArrowHead(return { left: arm(HEAD_ANGLE), right: arm(-HEAD_ANGLE) };}+export function inkArrowArmWidth(strokeWidth: number, release: number): number {+ return strokeWidth * release;+}++export function inkArrowApex(+ c2: InkArrowPoint,+ to: InkArrowPoint,+ reach: number,+): InkArrowPoint {+ const dx = to.x - c2.x;+ const dy = to.y - c2.y;+ const length = Math.hypot(dx, dy) || 1;+ return {+ x: to.x + (dx / length) * reach * ARM_OVERSHOOT,+ y: to.y + (dy / length) * reach * ARM_OVERSHOOT,+ };+}++export function inkArrowHeadReach(+ headSize: number,+ strokeWidth: number,+): number {+ return Math.max(headSize, strokeWidth * HEAD_MIN_RATIO);+}+export function inkArrowViewport(from: InkArrowPoint,to: InkArrowPoint,curvature: number,headSize: number,strokeWidth: number,+ grain = 1,): { width: number; height: number } {const distance = Math.hypot(to.x - from.x, to.y - from.y);- const margin = headSize + Math.abs(curvature) * distance + strokeWidth;+ const margin =+ inkArrowHeadReach(headSize, strokeWidth) ++ Math.abs(curvature) * distance ++ brushReach(strokeWidth, grain);return {width: Math.max(margin, Math.max(from.x, to.x) + margin),height: Math.max(margin, Math.max(from.y, to.y) + margin),@@ -79,6 +120,9 @@ export interface InkArrowProps {curvature?: number;color?: string;strokeWidth?: number;+ pressure?: number;+ release?: number;+ grain?: number;delay?: number;drawDur?: number;headSize?: number;@@ -92,7 +136,10 @@ export function InkArrow({to,curvature = 0.35,color = "#26242c",- strokeWidth = 3,+ strokeWidth = 8,+ pressure = 0.2,+ release = 1,+ grain = 1,delay = 0,drawDur = 36,headSize = 24,@@ -101,22 +148,17 @@ export function InkArrow({step = DEFAULT_STEP,}: InkArrowProps) {const frame = useCurrentFrame();- const progress = steppedRamp(frame, delay, delay + drawDur, {- ease: easeOutCubic,- step,- });+ const progress = steppedRamp(frame, delay, delay + drawDur, { step });const { c1, c2 } = inkArrowControls(from, to, curvature, seed);- const head = inkArrowHead(c2, to, headSize);+ const headReach = inkArrowHeadReach(headSize, strokeWidth);+ const head = inkArrowHead(c2, to, headReach);+ const apex = inkArrowApex(c2, to, headReach);const headFrames = headDur ?? step * 4;const headStart = delay + drawDur;const headMid = headStart + headFrames / 2;- const leftArm = steppedRamp(frame, headStart, headMid, {- ease: easeOutCubic,- step,- });+ const leftArm = steppedRamp(frame, headStart, headMid, { step });const rightArm = steppedRamp(frame, headMid, headStart + headFrames, {- ease: easeOutCubic,step,});@@ -126,8 +168,20 @@ export function InkArrow({curvature,headSize,strokeWidth,+ grain,);+ const filterId = brushFilterId(seed, strokeWidth, grain);+ const filter = grain > 0 ? `url(#${filterId})` : undefined;++ const armRibbon = (tip: InkArrowPoint, armProgress: number) =>+ brushRibbon(sampleLine(apex, tip, ARM_SAMPLES), {+ strokeWidth: inkArrowArmWidth(strokeWidth, release),+ pressure: 1,+ release: ARM_TAPER,+ progress: armProgress,+ });+return (<svgwidth={width}@@ -139,36 +193,35 @@ export function InkArrow({opacity: progress > 0 ? 1 : 0,}}>+ <title>Ink arrow</title>+ <BrushGrain seed={seed} strokeWidth={strokeWidth} grain={grain} /><path- d={`M ${from.x} ${from.y} C ${c1.x} ${c1.y}, ${c2.x} ${c2.y}, ${to.x} ${to.y}`}- stroke={color}- strokeWidth={strokeWidth}- strokeLinecap="round"- fill="none"- pathLength={1}- strokeDasharray={1}- strokeDashoffset={1 - progress}- />- <path- d={`M ${to.x} ${to.y} L ${head.left.x} ${head.left.y}`}- stroke={color}- strokeWidth={strokeWidth}- strokeLinecap="round"- fill="none"- pathLength={1}- strokeDasharray={1}- strokeDashoffset={1 - leftArm}- />- <path- d={`M ${to.x} ${to.y} L ${head.right.x} ${head.right.y}`}- stroke={color}- strokeWidth={strokeWidth}- strokeLinecap="round"- fill="none"- pathLength={1}- strokeDasharray={1}- strokeDashoffset={1 - rightArm}+ d={brushRibbon(sampleCubic(from, c1, c2, to, SHAFT_SAMPLES), {+ strokeWidth,+ pressure,+ release,+ progress,+ })}+ fill={color}+ opacity={0.85}+ filter={filter}/>+ {leftArm > 0 ? (+ <path+ d={armRibbon(head.left, leftArm)}+ fill={color}+ opacity={0.85}+ filter={filter}+ />+ ) : null}+ {rightArm > 0 ? (+ <path+ d={armRibbon(head.right, rightArm)}+ fill={color}+ opacity={0.85}+ filter={filter}+ />+ ) : null}</svg>);}diff --git a/registry/remocn/ink-underline/config.ts b/registry/remocn/ink-underline/config.tsindex 166b8421..884e31f6 100644--- a/registry/remocn/ink-underline/config.ts+++ b/registry/remocn/ink-underline/config.ts@@ -20,7 +20,31 @@ export const inkUnderlineConfig: ComponentConfig = {min: 2,max: 24,step: 1,- label: "Thickness",+ label: "Brush width",+ },+ pressure: {+ type: "number",+ default: 1,+ min: 0.05,+ max: 1,+ step: 0.05,+ label: "Opening pressure",+ },+ release: {+ type: "number",+ default: 0.15,+ min: 0.05,+ max: 1,+ step: 0.05,+ label: "Closing pressure",+ },+ grain: {+ type: "number",+ default: 1,+ min: 0,+ max: 2,+ step: 0.1,+ label: "Grain",},durationSteps: {type: "number",diff --git a/registry/remocn/ink-underline/index.tsx b/registry/remocn/ink-underline/index.tsxindex 611fc0e1..126bbbb6 100644--- a/registry/remocn/ink-underline/index.tsx+++ b/registry/remocn/ink-underline/index.tsx@@ -1,14 +1,41 @@"use client";import { useCurrentFrame } from "remotion";+import {+ BrushGrain,+ type BrushPoint,+ brushFilterId,+ brushReach,+ brushRibbon,+ sampleCubic,+} from "@/components/remocn/brush";import { DEFAULT_STEP, hashRange, steppedRamp } from "@/lib/remocn/stop-motion";-const easeOutCubic = (t: number) => 1 - (1 - t) ** 3;+const SAMPLES = 40;++export function inkUnderlineSpine(+ width: number,+ thickness: number,+ seed: string,+): BrushPoint[] {+ const wobble = hashRange(`${seed}:w`, -1.2, 1.2);+ const mid = thickness / 2 + 2;+ return sampleCubic(+ { x: 2, y: mid },+ { x: width * 0.3, y: mid + wobble },+ { x: width * 0.7, y: mid - wobble },+ { x: width - 2, y: mid + wobble * 0.6 },+ SAMPLES,+ );+}export interface InkUnderlineProps {width: number;color?: string;thickness?: number;+ pressure?: number;+ release?: number;+ grain?: number;delay?: number;durationSteps?: number;seed?: string;@@ -19,6 +46,9 @@ export function InkUnderline({width,color = "#6f7f35",thickness = 9,+ pressure = 1,+ release = 0.15,+ grain = 1,delay = 0,durationSteps = 5,seed = "ink",@@ -26,12 +56,17 @@ export function InkUnderline({}: InkUnderlineProps) {const frame = useCurrentFrame();const progress = steppedRamp(frame, delay, delay + durationSteps * step, {- ease: easeOutCubic,step,});- const wobble = hashRange(`${seed}:w`, -1.2, 1.2);++ const reach = brushReach(thickness, grain);const height = thickness + 4;- const mid = thickness / 2 + 2;+ const d = brushRibbon(inkUnderlineSpine(width, thickness, seed), {+ strokeWidth: thickness,+ pressure,+ release,+ progress,+ });return (<div@@ -43,21 +78,28 @@ export function InkUnderline({}}><svg- width={width}- height={height}- viewBox={`0 0 ${width} ${height}`}- style={{ display: "block", overflow: "visible" }}+ width={width + reach * 2}+ height={height + reach * 2}+ viewBox={`${-reach} ${-reach} ${width + reach * 2} ${height + reach * 2}`}+ style={{+ position: "absolute",+ left: -reach,+ top: -reach,+ display: "block",+ overflow: "visible",+ }}>+ <title>Ink underline</title>+ <BrushGrain seed={seed} strokeWidth={thickness} grain={grain} /><path- d={`M 2 ${mid} C ${width * 0.3} ${mid + wobble}, ${width * 0.7} ${mid - wobble}, ${width - 2} ${mid + wobble * 0.6}`}- stroke={color}- strokeWidth={thickness}- strokeLinecap="round"- fill="none"- pathLength={1}- strokeDasharray={1}- strokeDashoffset={1 - progress}- opacity={0.82}+ d={d}+ fill={color}+ opacity={0.85}+ filter={+ grain > 0+ ? `url(#${brushFilterId(seed, thickness, grain)})`+ : undefined+ }/></svg></div>diff --git a/registry/remocn/registry.json b/registry/remocn/registry.jsonindex 8732b35c..f06c195b 100644--- a/registry/remocn/registry.json+++ b/registry/remocn/registry.json@@ -1302,9 +1302,9 @@"name": "ink-underline","type": "registry:component","title": "Ink Underline",- "description": "A hand-dragged ink stroke that draws itself across in a few stop-motion poses, with a per-seed wobble.",+ "description": "A hand-dragged brush underline that sweeps itself across in a few stop-motion poses, thinning to a dry tail.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "ink-underline/index.tsx",@@ -1332,9 +1332,9 @@"name": "ink-arrow","type": "registry:component","title": "Ink Arrow",- "description": "A hand-drawn arrow that draws itself from one point to another in stop-motion poses, with the head popping on the final pose.",+ "description": "A hand-drawn brush arrow that sweeps itself from one point to another, thickening into the head that pops on the final poses.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "ink-arrow/index.tsx",@@ -1373,13 +1373,27 @@}]},+ {+ "name": "brush",+ "type": "registry:component",+ "title": "Brush",+ "description": "Variable-width brush ribbons for Remotion. Pressure taper, grain displacement, and spine samplers shared by the ink marks.",+ "registryDependencies": ["@remocn/stop-motion"],+ "files": [+ {+ "path": "brush/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/brush.tsx"+ }+ ]+ },{"name": "scribble-circle","type": "registry:component","title": "Scribble Circle","description": "A brush circle swept around a region of the frame, opening thin and closing thick, with grain breaking up the dry opening.","dependencies": ["remotion"],- "registryDependencies": ["@remocn/stop-motion"],+ "registryDependencies": ["@remocn/stop-motion", "@remocn/brush"],"files": [{"path": "scribble-circle/index.tsx",diff --git a/registry/remocn/scribble-circle/__tests__/scribble-circle.test.ts b/registry/remocn/scribble-circle/__tests__/scribble-circle.test.tsindex 71bcb314..395fa0d7 100644--- a/registry/remocn/scribble-circle/__tests__/scribble-circle.test.ts+++ b/registry/remocn/scribble-circle/__tests__/scribble-circle.test.ts@@ -1,10 +1,9 @@import { describe, expect, it } from "bun:test";+import { brushReach } from "@/components/remocn/brush";import { scribbleCircleConfig } from "../config";import {scribbleCircleCentre,- scribbleCircleGrainScale,- scribbleCircleHalfWidth,scribbleCirclePath,scribbleCirclePoints,scribbleCircleProgress,@@ -82,33 +81,6 @@ describe("scribbleCircleProgress", () => {});});-describe("scribbleCircleHalfWidth", () => {- it("opens at the pressure fraction and closes at the full brush", () => {- expect(scribbleCircleHalfWidth(STROKE, 0.2, 0)).toBeCloseTo(1.4);- expect(scribbleCircleHalfWidth(STROKE, 0.2, 1)).toBeCloseTo(7);- });-- it("thickens monotonically along the stroke", () => {- let previous = -1;- for (let i = 0; i <= 20; i++) {- const half = scribbleCircleHalfWidth(STROKE, 0.2, i / 20);- expect(half).toBeGreaterThan(previous);- previous = half;- }- });-- it("gives a uniform brush at pressure 1", () => {- for (const t of [0, 0.3, 0.7, 1]) {- expect(scribbleCircleHalfWidth(STROKE, 1, t)).toBeCloseTo(STROKE / 2);- }- });-- it("stays thinner than the grain displacement at the opening, so the tail breaks up", () => {- const opening = scribbleCircleHalfWidth(STROKE, 0.2, 0);- expect(opening * 2).toBeLessThan(scribbleCircleGrainScale(STROKE, 1));- });-});-describe("scribbleCirclePath", () => {it("is deterministic for a seed", () => {const a = scribbleCirclePath({ width: W, height: H, strokeWidth: STROKE });@@ -167,7 +139,7 @@ describe("scribbleCirclePath", () => {height: H,strokeWidth: STROKE,});- const reach = STROKE / 2 + scribbleCircleGrainScale(STROKE, 1) / 2;+ const reach = brushReach(STROKE, 1);expect(marginX).toBeCloseTo(reach + (W / 2) * 0.035 + W * 0.02);expect(marginY).toBeCloseTo(reach + (H / 2) * 0.035 + H * 0.02);expect(marginX).not.toBeCloseTo(marginY);diff --git a/registry/remocn/scribble-circle/index.tsx b/registry/remocn/scribble-circle/index.tsxindex 510b8fbc..a4895528 100644--- a/registry/remocn/scribble-circle/index.tsx+++ b/registry/remocn/scribble-circle/index.tsx@@ -2,18 +2,17 @@import { useCurrentFrame } from "remotion";import {- DEFAULT_STEP,- hash01,- hashRange,- steppedRamp,-} from "@/lib/remocn/stop-motion";+ BrushGrain,+ type BrushPoint,+ brushFilterId,+ brushReach,+ brushRibbon,+} from "@/components/remocn/brush";+import { DEFAULT_STEP, hashRange, steppedRamp } from "@/lib/remocn/stop-motion";const SAMPLES_PER_LAP = 48;const NOISE = 0.035;const CENTRE = 0.02;-const GRAIN_RATIO = 0.5;--export type ScribblePoint = { x: number; y: number };export type ScribbleCircleGeometry = {width: number;@@ -21,6 +20,7 @@ export type ScribbleCircleGeometry = {strokeWidth: number;laps?: number;pressure?: number;+ release?: number;grain?: number;seed?: string;points?: number;@@ -31,7 +31,7 @@ export function scribbleCircleCentre(width: number,height: number,seed = "scribble",-): ScribblePoint {+): BrushPoint {return {x: width / 2 + hashRange(`${seed}:cx`, -CENTRE, CENTRE) * width,y: height / 2 + hashRange(`${seed}:cy`, -CENTRE, CENTRE) * height,@@ -44,7 +44,7 @@ export function scribbleCirclePoints(args: {laps?: number;seed?: string;points?: number;-}): ScribblePoint[] {+}): BrushPoint[] {const laps = args.laps ?? 1.15;const seed = args.seed ?? "scribble";const points = args.points ?? SAMPLES_PER_LAP;@@ -64,81 +64,24 @@ export function scribbleCirclePoints(args: {});}-export function scribbleCircleHalfWidth(- strokeWidth: number,- pressure: number,- t: number,-): number {- return (strokeWidth / 2) * (pressure + (1 - pressure) * t);-}--export function scribbleCircleGrainScale(- strokeWidth: number,- grain: number,-): number {- return strokeWidth * GRAIN_RATIO * grain;-}--const normalAt = (points: ScribblePoint[], i: number): ScribblePoint => {- const before = points[i - 1] ?? points[i];- const after = points[i + 1] ?? points[i];- const tx = after.x - before.x;- const ty = after.y - before.y;- const length = Math.hypot(tx, ty) || 1;- return { x: -ty / length, y: tx / length };-};--const curveSegments = (points: ScribblePoint[]): string =>- points- .slice(0, -1)- .map((p1, i) => {- const p0 = points[i - 1] ?? p1;- const p2 = points[i + 1];- const p3 = points[i + 2] ?? p2;- return `C ${p1.x + (p2.x - p0.x) / 6} ${p1.y + (p2.y - p0.y) / 6}, ${p2.x - (p3.x - p1.x) / 6} ${p2.y - (p3.y - p1.y) / 6}, ${p2.x} ${p2.y}`;- })- .join(" ");-export function scribbleCirclePath(args: ScribbleCircleGeometry): {d: string;viewBox: string;marginX: number;marginY: number;} {- const pressure = args.pressure ?? 0.2;const grain = args.grain ?? 1;- const progress = args.progress ?? 1;- const spine = scribbleCirclePoints(args);- const drawn = Math.max(2, Math.round(progress * (spine.length - 1)) + 1);-- const left: ScribblePoint[] = [];- const right: ScribblePoint[] = [];- for (let i = 0; i < drawn; i++) {- const half = scribbleCircleHalfWidth(- args.strokeWidth,- pressure,- i / (spine.length - 1),- );- const normal = normalAt(spine, i);- left.push({- x: spine[i].x + normal.x * half,- y: spine[i].y + normal.y * half,- });- right.push({- x: spine[i].x - normal.x * half,- y: spine[i].y - normal.y * half,- });- }- const back = right.slice().reverse();-- const reach =- args.strokeWidth / 2 +- scribbleCircleGrainScale(args.strokeWidth, grain) / 2;+ const reach = brushReach(args.strokeWidth, grain);const marginX = reach + (args.width / 2) * NOISE + args.width * CENTRE;const marginY = reach + (args.height / 2) * NOISE + args.height * CENTRE;return {- d: `M ${left[0].x} ${left[0].y} ${curveSegments(left)} L ${back[0].x} ${back[0].y} ${curveSegments(back)} Z`,+ d: brushRibbon(scribbleCirclePoints(args), {+ strokeWidth: args.strokeWidth,+ pressure: args.pressure,+ release: args.release,+ progress: args.progress,+ }),viewBox: `${-marginX} ${-marginY} ${args.width + marginX * 2} ${args.height + marginY * 2}`,marginX,marginY,@@ -161,6 +104,7 @@ export interface ScribbleCircleProps {color?: string;strokeWidth?: number;pressure?: number;+ release?: number;grain?: number;delay?: number;durationSteps?: number;@@ -175,6 +119,7 @@ export function ScribbleCircle({color = "#6f7f35",strokeWidth = 14,pressure = 0.2,+ release = 1,grain = 1,delay = 0,durationSteps = 10,@@ -194,14 +139,12 @@ export function ScribbleCircle({strokeWidth,laps,pressure,+ release,grain,seed,progress,});- const grainScale = scribbleCircleGrainScale(strokeWidth, grain);- const filterId = `scribble-grain-${Math.floor(hash01(seed) * 1e9)}`;-return (<divstyle={{@@ -224,36 +167,16 @@ export function ScribbleCircle({}}><title>Scribbled circle</title>- <defs>- <filter- id={filterId}- x="-30%"- y="-30%"- width="160%"- height="160%"- filterUnits="objectBoundingBox"- >- <feTurbulence- type="fractalNoise"- baseFrequency="0.7"- numOctaves={3}- seed={Math.floor(hash01(`${seed}:grain`) * 1000)}- result="grain"- />- <feDisplacementMap- in="SourceGraphic"- in2="grain"- scale={grainScale}- xChannelSelector="R"- yChannelSelector="G"- />- </filter>- </defs>+ <BrushGrain seed={seed} strokeWidth={strokeWidth} grain={grain} /><pathd={d}fill={color}opacity={0.85}- filter={grain > 0 ? `url(#${filterId})` : undefined}+ filter={+ grain > 0+ ? `url(#${brushFilterId(seed, strokeWidth, grain)})`+ : undefined+ }/></svg></div>diff --git a/tsconfig.json b/tsconfig.jsonindex 4e7497fd..977a26bb 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -24,6 +24,7 @@"@/lib/remocn-ui": ["./registry/remocn-ui/core/index.ts"],"@/lib/remocn-ui/*": ["./registry/remocn-ui/core/*"],"@/lib/remocn/stop-motion": ["./registry/remocn/stop-motion/index.ts"],+ "@/components/remocn/brush": ["./registry/remocn/brush/index.tsx"],"@/components/remocn/handwrite": ["./registry/remocn/handwrite/index.tsx"],