🎥 Make videos programmatically with React
heart component
Jonny Burger22df8f35ed38
diff --git a/packages/docs/components/demos/Heart.tsx b/packages/docs/components/demos/Heart.tsxindex 72bab2f70b..d63e04ab29 100644--- a/packages/docs/components/demos/Heart.tsx+++ b/packages/docs/components/demos/Heart.tsx@@ -4,9 +4,21 @@ import {AbsoluteFill} from 'remotion';export const HeartDemo: React.FC<{readonly darkMode: boolean;- readonly width: number;+ readonly aspectRatio: number;readonly height: number;-}> = ({width, height, darkMode}) => {+ readonly bottomRoundnessAdjustment: number;+ readonly depthAdjustment: number;+ readonly debug: boolean;+ readonly showStrokeInsteadPlaygroundOnly: boolean;+}> = ({+ aspectRatio,+ height,+ darkMode,+ bottomRoundnessAdjustment,+ depthAdjustment,+ debug,+ showStrokeInsteadPlaygroundOnly,+}) => {return (<AbsoluteFillstyle={{@@ -15,10 +27,27 @@ export const HeartDemo: React.FC<{}}><Heart- fill={darkMode ? 'white' : 'var(--ifm-link-color)'}- width={width}+ fill={+ showStrokeInsteadPlaygroundOnly+ ? 'transparent'+ : darkMode+ ? 'white'+ : 'var(--ifm-link-color)'+ }+ aspectRatio={aspectRatio}height={height}- debug+ bottomRoundnessAdjustment={bottomRoundnessAdjustment}+ depthAdjustment={depthAdjustment}+ debug={debug}+ stroke={+ showStrokeInsteadPlaygroundOnly+ ? darkMode+ ? 'white'+ : 'var(--ifm-link-color)'+ : 'transparent'+ }+ strokeWidth={height / 20}+ strokeMiterlimit={1000000}/></AbsoluteFill>);diff --git a/packages/docs/components/demos/Pie.tsx b/packages/docs/components/demos/Pie.tsxindex 5fc3a9bb0e..a859c0c302 100644--- a/packages/docs/components/demos/Pie.tsx+++ b/packages/docs/components/demos/Pie.tsx@@ -1,47 +1,47 @@-import { Pie } from "@remotion/shapes";-import React from "react";-import { AbsoluteFill } from "remotion";+import {Pie} from '@remotion/shapes';+import React from 'react';+import {AbsoluteFill} from 'remotion';export const PieDemo: React.FC<{- readonly radius: number;- readonly darkMode: boolean;- readonly progress: number;- readonly closePath: boolean;- readonly showStrokeInsteadPreviewOnly: boolean;- readonly counterClockwise: boolean;- readonly rotation: number;+ readonly radius: number;+ readonly darkMode: boolean;+ readonly progress: number;+ readonly closePath: boolean;+ readonly showStrokeInsteadPlaygroundOnly: boolean;+ readonly counterClockwise: boolean;+ readonly rotation: number;}> = ({- radius,- darkMode,- progress,- closePath,- showStrokeInsteadPreviewOnly,- counterClockwise,- rotation,+ radius,+ darkMode,+ progress,+ closePath,+ showStrokeInsteadPlaygroundOnly,+ counterClockwise,+ rotation,}) => {- return (- <AbsoluteFill- style={{- justifyContent: "center",- alignItems: "center",- }}- >- <Pie- progress={progress}- fill={- showStrokeInsteadPreviewOnly- ? "transparent"- : darkMode- ? "white"- : "var(--ifm-link-color)"- }- radius={radius}- closePath={closePath}- stroke={darkMode ? "white" : "var(--ifm-link-color)"}- strokeWidth={showStrokeInsteadPreviewOnly ? 5 : 0}- counterClockwise={counterClockwise}- rotation={rotation}- />- </AbsoluteFill>- );+ return (+ <AbsoluteFill+ style={{+ justifyContent: 'center',+ alignItems: 'center',+ }}+ >+ <Pie+ progress={progress}+ fill={+ showStrokeInsteadPlaygroundOnly+ ? 'transparent'+ : darkMode+ ? 'white'+ : 'var(--ifm-link-color)'+ }+ radius={radius}+ closePath={closePath}+ stroke={darkMode ? 'white' : 'var(--ifm-link-color)'}+ strokeWidth={showStrokeInsteadPlaygroundOnly ? 5 : 0}+ counterClockwise={counterClockwise}+ rotation={rotation}+ />+ </AbsoluteFill>+ );};diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex 9abf21c7bf..9c1cec4d2d 100644--- a/packages/docs/components/demos/types.ts+++ b/packages/docs/components/demos/types.ts@@ -198,22 +198,52 @@ export const heartDemo: DemoType = {autoPlay: false,options: [{- default: 110,+ default: 300,max: 1000,step: 5,min: 1,type: 'numeric',- name: 'width',+ name: 'height',optional: 'no',},{- default: 100,- max: 1000,- step: 5,- min: 1,+ default: 1.1,+ max: 2,+ step: 0.01,+ min: 0.5,type: 'numeric',- name: 'height',+ name: 'aspectRatio',+ optional: 'no',+ },+ {+ default: 0,+ max: 0.2,+ step: 0.01,+ min: -0.2,+ type: 'numeric',+ name: 'depthAdjustment',+ optional: 'no',+ },+ {+ default: 0,+ max: 0.3,+ step: 0.01,+ min: -0.3,+ type: 'numeric',+ name: 'bottomRoundnessAdjustment',+ optional: 'no',+ },+ {+ type: 'boolean',+ name: 'debug',+ optional: 'no',+ default: true,+ },+ {+ type: 'boolean',+ name: 'showStrokeInsteadPlaygroundOnly',optional: 'no',+ default: true,},],};@@ -383,7 +413,7 @@ export const pieDemo: DemoType = {{default: false,type: 'boolean',- name: 'showStrokeInsteadPreviewOnly',+ name: 'showStrokeInsteadPlaygroundOnly',optional: 'no',},],diff --git a/packages/docs/components/shapes/shapes-info.tsx b/packages/docs/components/shapes/shapes-info.tsxindex 0a602ce158..f0a3428c15 100644--- a/packages/docs/components/shapes/shapes-info.tsx+++ b/packages/docs/components/shapes/shapes-info.tsx@@ -60,9 +60,26 @@ export const shapeComponents: ShapeComponent[] = [fn: makeHeart,params: [{- name: 'size',+ name: 'height',+ type: 'number',+ description: 'The height of the heart.',+ },+ {+ name: 'aspectRatio',+ type: 'number',+ description: 'The aspect ratio of the heart. Default 1.1.',+ },+ {+ name: 'bottomRoundnessAdjustment',+ type: 'number',+ description:+ 'The amount of bottom roundness deviation from the default. Negative values make the bottom point sharper, positive values make it rounder.',+ },+ {+ name: 'depthAdjustment',type: 'number',- description: 'The size of the heart.',+ description:+ 'The deviation of the default depth (how deep the top of the heart is). Negative values make the heart deeper, positive values make it shallower.',},],},diff --git a/packages/docs/docs/shapes/heart.mdx b/packages/docs/docs/shapes/heart.mdxindex 317a131c58..a4e7e740c3 100644--- a/packages/docs/docs/shapes/heart.mdx+++ b/packages/docs/docs/shapes/heart.mdx@@ -1,11 +1,12 @@---+image: /generated/articles-docs-shapes-heart.pngtitle: <Heart />crumb: '@remotion/shapes'---import {ShapeSeeAlso, ShapeOptions} from '../../components/shapes/shapes-info';-_Part of the [`@remotion/shapes`](/docs/shapes) package._+_available from v4.0.315_Renders an SVG element containing a heart.@@ -40,4 +41,4 @@ export const MyComposition = () => {## See also-<ShapeSeeAlso shape="heart" />\ No newline at end of file+<ShapeSeeAlso shape="heart" />diff --git a/packages/docs/docs/shapes/make-heart.mdx b/packages/docs/docs/shapes/make-heart.mdxindex ee90a426c0..30593d8aae 100644--- a/packages/docs/docs/shapes/make-heart.mdx+++ b/packages/docs/docs/shapes/make-heart.mdx@@ -1,11 +1,12 @@---+image: /generated/articles-docs-shapes-make-heart.pngtitle: makeHeart()crumb: '@remotion/shapes'---import {MakeShapeSeeAlso, ShapeOptions} from '../../components/shapes/shapes-info';-_Part of the [`@remotion/shapes`](/docs/shapes) package._+_available from v4.0.315_Generates an SVG path for a heart.diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 2e3a289fe1..a7ce6d68d1 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -4586,6 +4586,15 @@ export const articles = [noAi: false,slug: 'shapes/ellipse',},+ {+ id: 'shapes/heart',+ title: '<Heart />',+ relativePath: 'docs/shapes/heart.mdx',+ compId: 'articles-docs-shapes-heart',+ crumb: '@remotion/shapes',+ noAi: false,+ slug: 'shapes/heart',+ },{id: 'shapes/index',title: '@remotion/shapes',@@ -4613,6 +4622,15 @@ export const articles = [noAi: false,slug: 'shapes/make-ellipse',},+ {+ id: 'shapes/make-heart',+ title: 'makeHeart()',+ relativePath: 'docs/shapes/make-heart.mdx',+ compId: 'articles-docs-shapes-make-heart',+ crumb: '@remotion/shapes',+ noAi: false,+ slug: 'shapes/make-heart',+ },{id: 'shapes/make-pie',title: 'makePie()',diff --git a/packages/docs/static/generated/articles-docs-shapes-heart.png b/packages/docs/static/generated/articles-docs-shapes-heart.pngnew file mode 100644index 0000000000..1235fa6caaBinary files /dev/null and b/packages/docs/static/generated/articles-docs-shapes-heart.png differdiff --git a/packages/docs/static/generated/articles-docs-shapes-make-heart.png b/packages/docs/static/generated/articles-docs-shapes-make-heart.pngnew file mode 100644index 0000000000..858f2ed96bBinary files /dev/null and b/packages/docs/static/generated/articles-docs-shapes-make-heart.png differdiff --git a/packages/shapes/src/components/heart.tsx b/packages/shapes/src/components/heart.tsxindex 87e5b94cd9..3b1331bd0b 100644--- a/packages/shapes/src/components/heart.tsx+++ b/packages/shapes/src/components/heart.tsx@@ -11,6 +11,22 @@ export type HeartProps = MakeHeartProps & AllShapesProps;* @param {Number} size The size of the heart.* @see [Documentation](https://www.remotion.dev/docs/shapes/heart)*/-export const Heart: React.FC<HeartProps> = ({width, height, ...props}) => {- return <RenderSvg {...makeHeart({width, height})} {...props} />;+export const Heart: React.FC<HeartProps> = ({+ aspectRatio,+ height,+ bottomRoundnessAdjustment = 0,+ depthAdjustment = 0,+ ...props+}) => {+ return (+ <RenderSvg+ {...makeHeart({+ aspectRatio,+ height,+ bottomRoundnessAdjustment,+ depthAdjustment,+ })}+ {...props}+ />+ );};diff --git a/packages/shapes/src/test/heart.test.tsx b/packages/shapes/src/test/heart.test.tsxindex a0faceb2da..b1f94a2ec1 100644--- a/packages/shapes/src/test/heart.test.tsx+++ b/packages/shapes/src/test/heart.test.tsx@@ -3,7 +3,14 @@ import {Heart} from '../components/heart';import {render} from './test-utils';test('Should be able to make a heart svg', () => {- const {container} = render(<Heart width={100} height={100} />);+ const {container} = render(+ <Heart+ aspectRatio={1.1}+ height={100}+ bottomRoundnessAdjustment={0}+ depthAdjustment={0}+ />,+ );expect(container.querySelector('path')?.getAttribute('d')?.startsWith('M 50 85 C'),diff --git a/packages/shapes/src/test/make-heart.test.ts b/packages/shapes/src/test/make-heart.test.tsindex 4b32786714..33d02160d0 100644--- a/packages/shapes/src/test/make-heart.test.ts+++ b/packages/shapes/src/test/make-heart.test.ts@@ -3,8 +3,10 @@ import {makeHeart} from '../utils/make-heart';test('Should be able to make a heart path', () => {const heartPath = makeHeart({- width: 100,+ aspectRatio: 1.1,height: 100,+ bottomRoundnessAdjustment: 0,+ depthAdjustment: 0,});expect(heartPath.width).toEqual(100);diff --git a/packages/shapes/src/utils/make-heart.ts b/packages/shapes/src/utils/make-heart.tsindex 24f1a649fe..f6a2edee89 100644--- a/packages/shapes/src/utils/make-heart.ts+++ b/packages/shapes/src/utils/make-heart.ts@@ -3,8 +3,10 @@ import {serializeInstructions} from '@remotion/paths';import type {ShapeInfo} from './shape-info';export type MakeHeartProps = {- width: number;height: number;+ aspectRatio: number;+ bottomRoundnessAdjustment: number;+ depthAdjustment: number;};/**@@ -12,15 +14,23 @@ export type MakeHeartProps = {* @param {Number} size The size of the heart.* @see [Documentation](https://www.remotion.dev/docs/shapes/make-heart)*/-export const makeHeart = ({width, height}: MakeHeartProps): ShapeInfo => {- const bottomControlPointX = (32 / 110) * width;+export const makeHeart = ({+ height,+ aspectRatio,+ bottomRoundnessAdjustment = 0,+ depthAdjustment = 0,+}: MakeHeartProps): ShapeInfo => {+ const width = height * aspectRatio;+ const bottomControlPointX =+ (23 / 110) * width + bottomRoundnessAdjustment * width;const bottomControlPointY = (69 / 100) * height;const bottomLeftControlPointY = (60 / 100) * height;- const topLeftControlPointY = (13 / 100) * height;- const topRightControlPointX = (40 / 110) * width;- const innerControlPointX = (50 / 110) * width;+ const topLeftControlPoint = (13 / 100) * height;+ const topBezierWidth = (29 / 110) * width;+ const topRightControlPointX = (15 / 110) * width;+ const innerControlPointX = (5 / 110) * width;const innerControlPointY = (7 / 100) * height;- const depth = (17 / 100) * height;+ const depth = (17 / 100) * height + depthAdjustment * height;const instructions: Instruction[] = [{@@ -30,7 +40,7 @@ export const makeHeart = ({width, height}: MakeHeartProps): ShapeInfo => {},{type: 'C',- cp1x: bottomControlPointX,+ cp1x: width / 2 - bottomControlPointX,cp1y: bottomControlPointY,cp2x: 0,cp2y: bottomLeftControlPointY,@@ -40,21 +50,51 @@ export const makeHeart = ({width, height}: MakeHeartProps): ShapeInfo => {{type: 'C',cp1x: 0,- cp1y: topLeftControlPointY,- cp2x: topLeftControlPointY,+ cp1y: topLeftControlPoint,+ cp2x: width / 4 - topBezierWidth / 2,cp2y: 0,x: width / 4,y: 0,},{type: 'C',- cp1x: topRightControlPointX,+ cp1x: width / 4 + topBezierWidth / 2,cp1y: 0,- cp2x: innerControlPointX,+ cp2x: width / 2 - innerControlPointX,cp2y: innerControlPointY,x: width / 2,y: depth,},+ {+ type: 'C',+ cp1x: width / 2 + innerControlPointX,+ cp1y: innerControlPointY,+ cp2x: width / 2 + topRightControlPointX,+ cp2y: 0,+ x: (width / 4) * 3,+ y: 0,+ },+ {+ type: 'C',+ cp1x: (width / 4) * 3 + topBezierWidth / 2,+ cp1y: 0,+ cp2x: width,+ cp2y: topLeftControlPoint,+ x: width,+ y: height / 4,+ },+ {+ type: 'C',+ x: width / 2,+ y: height,+ cp1x: width,+ cp1y: bottomLeftControlPointY,+ cp2x: width / 2 + bottomControlPointX,+ cp2y: bottomControlPointY,+ },+ {+ type: 'Z',+ },];const path = serializeInstructions(instructions);