🎥 Make videos programmatically with React
add another example
Jonny Burger2f7faa0bf4cf
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex b3622d875e..32fded5426 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -35,6 +35,7 @@ import {Greenscreen} from './VideoOnCanvas/greenscreen';import {VideoSpeed} from './VideoSpeed';import {VideoTesting} from './VideoTesting';import {WarpDemo} from './WarpText';+import {WarpDemo2} from './WarpText/demo2';if (alias !== 'alias') {throw new Error('should support TS aliases');@@ -532,6 +533,14 @@ export const Index: React.FC = () => {height={1080}width={1080}/>+ <Composition+ id="path-warp-2"+ component={WarpDemo2}+ durationInFrames={500}+ fps={30}+ height={1080}+ width={1080}+ /></Folder><Folder name="gif"><Compositiondiff --git a/packages/example/src/WarpText/demo2.tsx b/packages/example/src/WarpText/demo2.tsxnew file mode 100644index 0000000000..ddbaf2c692--- /dev/null+++ b/packages/example/src/WarpText/demo2.tsx@@ -0,0 +1,109 @@+import opentype from 'opentype.js';+import {useEffect, useRef, useState} from 'react';+import {AbsoluteFill, staticFile, useCurrentFrame} from 'remotion';++import {getBoundingBox, resetPath, warpPath, WarpPathFn} from '@remotion/paths';++type FontInfo = {+ path: string;+};++// Recreating the album cover typography from https://en.wikipedia.org/wiki/So_Good_(Zara_Larsson_album)+const getPath = () => {+ return new Promise<FontInfo>((resolve, reject) => {+ opentype.load(staticFile('Roboto-Medium.ttf'), (err, font) => {+ if (err) {+ reject(err);+ return;+ }+ if (!font) {+ reject(new Error('No font found'));+ return;+ }++ const path = font.getPath('SO GOOD', 0, 150, 72);+ const p = path.toPathData(2);+ resolve({path: p});+ });+ });+};++function normalDistribution(x: number): number {+ return Math.exp(-(x ** 2) / 2) / Math.sqrt(2 * Math.PI);+}++console.log('hi');+console.log(normalDistribution(-1));+console.log(normalDistribution(0.5));+console.log(normalDistribution(1));+console.log('hi');++export const WarpDemo2 = () => {+ const [path, setPath] = useState<string | null>(() => null);+ const ref = useRef<SVGSVGElement>(null);+ const frame = useCurrentFrame();++ useEffect(() => {+ getPath().then((p) => {+ setPath(p.path);+ });+ }, [frame]);++ if (!path) {+ return null;+ }++ const reset = resetPath(path);++ const boundingBox = getBoundingBox(reset);+ const height = boundingBox.y2 - boundingBox.y1;++ const start = 0.4 * height;+ const end = 0.5 * height;++ const warpPathFn: WarpPathFn = ({x, y}) => {+ const currentPos = y - start;++ const ease = normalDistribution(currentPos / (end - start));++ return {+ x: x + 80 * ease,+ y: y * 5,+ };+ };++ const warped = warpPath(reset, warpPathFn, {+ interpolationThreshold: 0.3,+ });+ const box = getBoundingBox(warped);++ const {x1, x2, y1, y2} = box;++ return (+ <AbsoluteFill+ style={{+ backgroundColor: 'rgb(87 132 153)',+ justifyContent: 'center',+ alignItems: 'center',+ }}+ >+ {path ? (+ <svg+ ref={ref}+ style={{+ overflow: 'visible',+ height: 500,+ }}+ viewBox={`${x1} ${y1} ${x2 - x1} ${y2 - y1}`}+ >+ <path+ d={warped}+ fill="transparent"+ stroke="#E2BECC"+ strokeWidth={2}+ />+ </svg>+ ) : null}+ </AbsoluteFill>+ );+};diff --git a/packages/example/src/WarpText/index.tsx b/packages/example/src/WarpText/index.tsxindex a016ef9599..e956ec22df 100644--- a/packages/example/src/WarpText/index.tsx+++ b/packages/example/src/WarpText/index.tsx@@ -76,7 +76,7 @@ export const WarpDemo = () => {y: y * sprX,});- const warped = warpPath(reset, warpPathFn, 4);+ const warped = warpPath(reset, warpPathFn);const box = getBoundingBox(warped);const {x1, x2, y1, y2} = box;