🎥 Make videos programmatically with React
example
Jonny Burger86834f08ae26
diff --git a/packages/example/src/Paths/SlicePath.tsx b/packages/example/src/Paths/SlicePath.tsxnew file mode 100644index 0000000000..26fec99f0c--- /dev/null+++ b/packages/example/src/Paths/SlicePath.tsx@@ -0,0 +1,26 @@+import {cutPath, getLength} from '@remotion/paths';+import {makeStar} from '@remotion/shapes';+import React from 'react';+import {interpolate, useCurrentFrame} from 'remotion';++export const SlicePath: React.FC = () => {+ const frame = useCurrentFrame();++ const path = makeStar({+ points: 10,+ innerRadius: 100,+ outerRadius: 200,+ edgeRoundness: 0.5,+ });++ const progress = interpolate(frame, [0, 100], [0, 1]);+ const length = getLength(path.path);++ const cut = cutPath(path.path, length * progress);++ return (+ <svg viewBox={`0 0 ${path.width} ${path.height}`}>+ <path d={cut} stroke="black" strokeWidth={3} fill="none" />+ </svg>+ );+};diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex 5c24a1e064..20e943ef7f 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -37,6 +37,7 @@ import {} from './OffthreadRemoteVideo/OffthreadRemoteVideo';import {OrbScene} from './Orb';import {ShapesMorph} from './Paths/ShapesMorph';+import {SlicePath} from './Paths/SlicePath';import {PremountedExample} from './Premount';import {PremountedRemoteVideos} from './Premount/RemoteVideos';import InfinityVideo from './ReallyLongVideo';@@ -974,6 +975,14 @@ export const Index: React.FC = () => {height={1080}width={1080}/>+ <Composition+ id="slice-path"+ component={SlicePath}+ durationInFrames={500}+ fps={30}+ height={1080}+ width={1080}+ /></Folder><Folder name="gif"><Compositiondiff --git a/packages/paths/src/cut-path.ts b/packages/paths/src/cut-path.tsindex d8d649d4b9..7691a30f25 100644--- a/packages/paths/src/cut-path.ts+++ b/packages/paths/src/cut-path.ts@@ -3,8 +3,9 @@ import {conductAnalysis} from './helpers/reduced-analysis';import type {ReducedInstruction} from './helpers/types';import {parsePath} from './parse-path';import {reduceInstructions} from './reduce-instructions';+import {serializeInstructions} from './serialize-instructions';-export const cutPath = (d: string, length: number) => {+export const cutPath = (d: string, length: number): string => {const parsed = parsePath(d);const reduced = reduceInstructions(parsed);const constructed = conductAnalysis(reduced);@@ -25,13 +26,17 @@ export const cutPath = (d: string, length: number) => {progress,});newInstructions.push(cut);- return newInstructions;+ return serializeInstructions(newInstructions);}summedUpLength += instructionAndInfo.length;newInstructions.push(instructionAndInfo.instruction);++ if (summedUpLength === length) {+ return serializeInstructions(newInstructions);+ }}}- return newInstructions;+ return serializeInstructions(newInstructions);};diff --git a/packages/paths/src/index.ts b/packages/paths/src/index.tsindex d1dd6afef2..abdfeaef30 100644--- a/packages/paths/src/index.ts+++ b/packages/paths/src/index.ts@@ -1,6 +1,7 @@import {getBoundingBoxFromInstructions} from './get-bounding-box';import {debugPath} from './debug-path';+export {cutPath} from './cut-path';export {evolvePath} from './evolve-path';export {extendViewBox} from './extend-viewbox';export {getBoundingBox} from './get-bounding-box';