Loading...
Loading...
Smooth spline path animations for Remotion compositions — linear and Catmull-Rom splines with SVG path generation
npx skill4agent add oren-hollander/remotion-spline remotion-splineremotion-splineimport {
evaluateLinearSpline,
linearSplineToSVGPath,
evaluateCatmullRom,
catmullRomToSVGPath,
type Point2D,
} from "remotion-spline";interface Point2D {
readonly x: number;
readonly y: number;
}evaluateLinearSpline(points: Point2D[], t: number): [number, number]tpointslinearSplineToSVGPath(points: Point2D[]): stringM ... L ...evaluateCatmullRom(points: Point2D[], t: number): [number, number]tpointscatmullRomToSVGPath(points: Point2D[]): stringM ... C ...import { useCurrentFrame, useVideoConfig } from "remotion";
import { evaluateCatmullRom, catmullRomToSVGPath, type Point2D } from "remotion-spline";
const points: Point2D[] = [
{ x: 100, y: 500 },
{ x: 300, y: 200 },
{ x: 600, y: 400 },
];
export const MyAnimation: React.FC = () => {
const frame = useCurrentFrame();
const { durationInFrames } = useVideoConfig();
const t = frame / (durationInFrames - 1);
const [x, y] = evaluateCatmullRom(points, t);
const pathD = catmullRomToSVGPath(points);
return (
<svg viewBox="0 0 800 800">
{/* Static path */}
<path d={pathD} stroke="blue" strokeWidth="2" fill="none" />
{/* Animated dot */}
<circle cx={x} cy={y} r="10" fill="red" />
</svg>
);
};t=0t=1linearSplineToSVGPathcatmullRomToSVGPathevaluateLinearSplineevaluateCatmullRomt