Skip to content

🎥 Make videos programmatically with React

hmm

Jonny Burger8b466be53716
diff --git a/packages/example/src/Paths/ShapesMorph.tsx b/packages/example/src/Paths/ShapesMorph.tsx
index bc3e8311a9..36c04adb21 100644
--- a/packages/example/src/Paths/ShapesMorph.tsx
+++ b/packages/example/src/Paths/ShapesMorph.tsx
@@ -1,4 +1,4 @@
-import {interpolatePath} from '@remotion/paths';
+import {debugPath, interpolatePath} from '@remotion/paths';
import {makeCircle, makePolygon} from '@remotion/shapes';
import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
@@ -20,11 +20,15 @@ export const ShapesMorph: React.FC = () => {
});
const interpolated = interpolatePath(interpolation, polygonpath, circlepath);
+ const debugged = debugPath(interpolated);
return (
<AbsoluteFill className="bg-gray-100 items-center justify-center">
<svg viewBox="0 0 720 720">
<path d={interpolated} />
+ {debugged.map((debug) => {
+ return <path d={debug.d} fill={debug.color} />;
+ })}
</svg>
</AbsoluteFill>
);
diff --git a/packages/paths/src/debug-path.ts b/packages/paths/src/debug-path.ts
new file mode 100644
index 0000000000..dde7b8baf7
--- /dev/null
+++ b/packages/paths/src/debug-path.ts
@@ -0,0 +1,66 @@
+import type {Instruction} from './helpers/types';
+import {normalizeInstructions} from './normalize-path';
+import {parsePath} from './parse-path';
+import {serializeInstructions} from './serialize-instructions';
+
+type DebugInstruction = {
+ d: string;
+ color: string;
+};
+
+export const debugPath = (d: string) => {
+ const instructions = normalizeInstructions(parsePath(d));
+
+ return instructions
+ .map((inst, i): DebugInstruction | null => {
+ if (inst.type === 'Z') {
+ return null;
+ }
+
+ if (inst.type === 'H' || inst.type === 'V') {
+ return null;
+ }
+
+ const topLeft = [inst.x - 5, inst.y - 5];
+ const topRight = [inst.x + 5, inst.y - 5];
+ const bottomLeft = [inst.x - 5, inst.y + 5];
+ const bottomRight = [inst.x + 5, inst.y + 5];
+
+ const triangle: Instruction[] = [
+ {
+ type: 'M',
+ x: topLeft[0],
+ y: topLeft[1],
+ },
+ {
+ type: 'L',
+ x: topRight[0],
+ y: topRight[1],
+ },
+ {
+ type: 'L',
+ x: bottomRight[0],
+ y: bottomRight[1],
+ },
+ {
+ type: 'L',
+ x: bottomLeft[0],
+ y: bottomLeft[1],
+ },
+ {
+ type: 'Z',
+ },
+ ];
+
+ return {
+ d: serializeInstructions(triangle),
+ color:
+ i === instructions.length - 1
+ ? 'red'
+ : inst.type === 'M'
+ ? 'blue'
+ : 'green',
+ };
+ })
+ .filter(Boolean) as DebugInstruction[];
+};
diff --git a/packages/paths/src/index.ts b/packages/paths/src/index.ts
index eee8b447b1..c8ad09d315 100644
--- a/packages/paths/src/index.ts
+++ b/packages/paths/src/index.ts
@@ -1,5 +1,6 @@
import {getBoundingBoxFromInstructions} from './get-bounding-box';
+export {debugPath} from './debug-path';
export {evolvePath} from './evolve-path';
export {extendViewBox} from './extend-viewbox';
export {getBoundingBox} from './get-bounding-box';
@@ -25,7 +26,6 @@ export {scalePath} from './scale-path';
export {serializeInstructions} from './serialize-instructions';
export {translatePath} from './translate-path';
export {WarpPathFn, warpPath} from './warp-path';
-
export const PathInternals = {
getBoundingBoxFromInstructions,
};