Skip to content

🎥 Make videos programmatically with React

docs

Jonny Burger32550bd96869
diff --git a/packages/docs/components/shapes/edge-roundness.tsx b/packages/docs/components/shapes/edge-roundness.tsx
new file mode 100644
index 0000000000..840d7539d0
--- /dev/null
+++ b/packages/docs/components/shapes/edge-roundness.tsx
@@ -0,0 +1,166 @@
+import { Rect, Triangle } from "@remotion/shapes";
+import React from "react";
+
+const Header: React.FC = () => {
+ return (
+ <>
+ <h3>
+ <code>edgeRoundness</code>
+ </h3>
+ <p>
+ <em>null | number</em>
+ </p>
+ <p>
+ Allows to modify the shape by rounding the edges using bezier curves.
+ Default <code>null</code>.
+ </p>
+ </>
+ );
+};
+
+const Footer: React.FC = () => {
+ return (
+ <p>
+ Values below <code>0</code> and above <code>1</code> are possible{" "}
+ </p>
+ );
+};
+
+export const RectEdgeRoundness: React.FC = () => {
+ return (
+ <table>
+ <Header />
+ <tr>
+ <td>
+ <Rect fill="#0b84f3" debug edgeRoundness={0} height={80} width={80} />
+ </td>
+ <td>
+ <code>0</code> will lead to a rotated rectangle being drawn inside the
+ natural dimensions of the rectangle.
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <Rect
+ fill="#0b84f3"
+ debug
+ edgeRoundness={(4 * (Math.sqrt(2) - 1)) / 3}
+ height={80}
+ width={80}
+ />
+ </td>
+ <td>
+ <code>(4 * (Math.sqrt(2) - 1)) / 3</code> will{" "}
+ <a
+ target={
+ "https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%c3%a9zier-curves/27863181#27863181"
+ }
+ >
+ draw a circle
+ </a>
+ .
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <Rect fill="#0b84f3" debug edgeRoundness={1} height={80} width={80} />
+ </td>
+ <td>
+ <code>1</code> will draw a squircle.
+ </td>
+ </tr>
+ <tr>
+ <td
+ style={{
+ overflow: "hidden",
+ }}
+ >
+ <Rect fill="#0b84f3" debug edgeRoundness={2} height={80} width={80} />
+ </td>
+ <td>
+ Values below <code>0</code> and above <code>1</code> are possible and
+ may result in interesting shapes. Pictured: <code>2</code>
+ </td>
+ </tr>
+ </table>
+ );
+};
+
+export const TriangleEdgeRoundness = () => {
+ return (
+ <table>
+ <Header />
+ <tr>
+ <td>
+ <Triangle
+ fill="#0b84f3"
+ debug
+ edgeRoundness={0}
+ length={80}
+ direction="up"
+ />
+ </td>
+ <td>
+ <code>0</code> will lead to a rotated triangle being drawn inside the
+ natural dimensions of the triangle.
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <Triangle
+ fill="#0b84f3"
+ debug
+ edgeRoundness={Math.sqrt(2) - 1}
+ length={80}
+ direction="right"
+ />
+ </td>
+ <td>
+ <code>Math.sqrt(2) - 1</code> will{" "}
+ <a
+ target={
+ "https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%c3%a9zier-curves/27863181#27863181"
+ }
+ >
+ draw a circle
+ </a>
+ .
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <Triangle
+ fill="#0b84f3"
+ debug
+ edgeRoundness={1}
+ length={80}
+ direction="up"
+ />
+ </td>
+ <td>
+ <code>1</code> will draw a shape similar to a {'"squircle"'} but as a
+ triangle.
+ </td>
+ </tr>
+ <tr>
+ <td
+ style={{
+ overflow: "hidden",
+ }}
+ >
+ <Triangle
+ fill="#0b84f3"
+ debug
+ edgeRoundness={2}
+ length={80}
+ direction="up"
+ />
+ </td>
+ <td>
+ Values below <code>0</code> and above <code>1</code> may result in
+ other interesting shapes. Pictured: <code>2</code>.
+ </td>
+ </tr>
+ </table>
+ );
+};
diff --git a/packages/docs/components/shapes/rect-edge-roundness.tsx b/packages/docs/components/shapes/rect-edge-roundness.tsx
deleted file mode 100644
index b2ebc0b4ea..0000000000
--- a/packages/docs/components/shapes/rect-edge-roundness.tsx
+++ /dev/null
@@ -1,80 +0,0 @@
-import { Rect } from "@remotion/shapes";
-import React from "react";
-
-export const RectEdgeRoundness = () => {
- return (
- <>
- <h3>
- <code>edgeRoundness</code>
- </h3>
- <p>
- <em>null | number</em>
- </p>
- <p>
- Allows to modify the shape by rounding the edges using bezier curves.
- Default <code>null</code>.
- </p>
- <table>
- <tr>
- <td>
- <Rect
- fill="#0b84f3"
- debug
- edgeRoundness={0}
- height={80}
- width={80}
- />
- </td>
- <td>
- <code>0</code> will lead to a rotated rectangle being drawn inside
- the natural dimensions of the rectangle.
- </td>
- </tr>
- <tr>
- <td>
- <Rect
- fill="#0b84f3"
- debug
- edgeRoundness={(4 * (Math.sqrt(2) - 1)) / 3}
- height={80}
- width={80}
- />
- </td>
- <td>
- <code>(4 * (Math.sqrt(2) - 1)) / 3</code> will{" "}
- <a
- target={
- "https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%c3%a9zier-curves/27863181#27863181"
- }
- >
- draw a circle
- </a>
- .
- </td>
- </tr>
- <tr>
- <td>
- <Rect
- fill="#0b84f3"
- debug
- edgeRoundness={1}
- height={80}
- width={80}
- />
- </td>
- <td>
- <code>1</code> will{" "}
- <a
- target={
- "https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%c3%a9zier-curves/27863181#27863181"
- }
- >
- draw a squircle.
- </a>
- .
- </td>
- </tr>
- </table>
- </>
- );
-};
diff --git a/packages/docs/components/shapes/shapes-info.tsx b/packages/docs/components/shapes/shapes-info.tsx
index 49bb1fe982..a2988d7149 100644
--- a/packages/docs/components/shapes/shapes-info.tsx
+++ b/packages/docs/components/shapes/shapes-info.tsx
@@ -5,7 +5,7 @@ import {
makeTriangle,
} from "@remotion/shapes";
import React from "react";
-import { RectEdgeRoundness } from "./rect-edge-roundness";
+import { RectEdgeRoundness, TriangleEdgeRoundness } from "./edge-roundness";
type Param = {
name: string;
@@ -13,7 +13,7 @@ type Param = {
description: React.ReactNode;
};
-type ShapeComponent = {
+export type ShapeComponent = {
shape: string;
fn: (options: unknown) => unknown;
params: Param[];
@@ -179,7 +179,12 @@ export const ShapeOptions: React.FC<{
</React.Fragment>
);
})}
- <RectEdgeRoundness />
+ {shapeComponent.shape === "Rect" ? (
+ <RectEdgeRoundness component={shapeComponent} />
+ ) : null}
+ {shapeComponent.shape === "Triangle" ? (
+ <TriangleEdgeRoundness component={shapeComponent} />
+ ) : null}
{all ? (
<>
<h3>Other props</h3>{" "}
diff --git a/packages/docs/docs/shapes/triangle.md b/packages/docs/docs/shapes/triangle.md
index a6eb3735cf..581469b3f7 100644
--- a/packages/docs/docs/shapes/triangle.md
+++ b/packages/docs/docs/shapes/triangle.md
@@ -33,7 +33,7 @@ export const MyComposition = () => {
## Props
-<ShapeOptions shape="ellipse" all />
+<ShapeOptions shape="triangle" all />
## See also
diff --git a/packages/example/src/Shapes/RectTest.tsx b/packages/example/src/Shapes/RectTest.tsx
index ed43edd748..38aeb50641 100644
--- a/packages/example/src/Shapes/RectTest.tsx
+++ b/packages/example/src/Shapes/RectTest.tsx
@@ -1,22 +1,9 @@
import {Circle, Rect} from '@remotion/shapes';
import React from 'react';
-import {
- AbsoluteFill,
- interpolate,
- spring,
- useCurrentFrame,
- useVideoConfig,
-} from 'remotion';
+import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
const RectTest: React.FC = () => {
const frame = useCurrentFrame();
- const {fps} = useVideoConfig();
-
- const spr = spring({
- fps,
- frame,
- config: {},
- });
const edgeRoundness = interpolate(frame, [0, 100], [0, 1], {
extrapolateRight: 'clamp',
diff --git a/packages/example/src/Shapes/TriangleTest.tsx b/packages/example/src/Shapes/TriangleTest.tsx
index 89205b655b..d3197404f8 100644
--- a/packages/example/src/Shapes/TriangleTest.tsx
+++ b/packages/example/src/Shapes/TriangleTest.tsx
@@ -34,7 +34,7 @@ const TriangleTest: React.FC = () => {
debug
edgeRoundness={edgeRoundness}
length={100}
- direction="top"
+ direction="up"
/>
</AbsoluteFill>
);
diff --git a/packages/shapes/src/utils/make-triangle.ts b/packages/shapes/src/utils/make-triangle.ts
index 244808e2ae..457312a3ae 100644
--- a/packages/shapes/src/utils/make-triangle.ts
+++ b/packages/shapes/src/utils/make-triangle.ts
@@ -4,7 +4,7 @@ import {serializeInstructions} from './instructions';
import {joinPoints} from './join-points';
import type {ShapeInfo} from './shape-info';
-type Direction = 'right' | 'left' | 'top' | 'bottom';
+type Direction = 'right' | 'left' | 'up' | 'down';
export type MakeTriangleProps = {
length: number;
@@ -21,7 +21,7 @@ export const makeTriangle = ({
const shorterSize = Math.sqrt(length ** 2 * 0.75); // Calculated on paper;
const points: {[key in Direction]: [number, number][]} = {
- top: [
+ up: [
[longerDimension / 2, 0],
[0, shorterSize],
[longerDimension, shorterSize],
@@ -33,7 +33,7 @@ export const makeTriangle = ({
[shorterSize, longerDimension / 2],
[0, 0],
],
- bottom: [
+ down: [
[0, 0],
[longerDimension, 0],
[longerDimension / 2, shorterSize],
@@ -50,13 +50,13 @@ export const makeTriangle = ({
const transformOriginX = {
left: (shorterSize / 3) * 2,
right: shorterSize / 3,
- top: longerDimension / 2,
- bottom: longerDimension / 2,
+ up: longerDimension / 2,
+ down: longerDimension / 2,
}[direction];
const transformOriginY = {
- top: (shorterSize / 3) * 2,
- bottom: shorterSize / 3,
+ up: (shorterSize / 3) * 2,
+ down: shorterSize / 3,
left: longerDimension / 2,
right: longerDimension / 2,
}[direction];
@@ -67,9 +67,8 @@ export const makeTriangle = ({
return {
path,
instructions,
- width: direction === 'top' || direction === 'bottom' ? length : shorterSize,
- height:
- direction === 'top' || direction === 'bottom' ? shorterSize : length,
+ width: direction === 'up' || direction === 'down' ? length : shorterSize,
+ height: direction === 'up' || direction === 'down' ? shorterSize : length,
transformOrigin: `${transformOriginX} ${transformOriginY}`,
};
};