🎥 Make videos programmatically with React
star demo
Jonny Burger1f3a620b8aeb
diff --git a/packages/docs/components/demos/Star.tsx b/packages/docs/components/demos/Star.tsxnew file mode 100644index 0000000000..5cafc711ef--- /dev/null+++ b/packages/docs/components/demos/Star.tsx@@ -0,0 +1,27 @@+import { Star } from "@remotion/shapes";+import React from "react";+import { AbsoluteFill } from "remotion";++export const StarDemo: React.FC<{+ darkMode: boolean;+ innerRadius: number;+ outerRadius: number;+}> = ({ innerRadius, outerRadius, darkMode }) => {+ return (+ <AbsoluteFill+ style={{+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <Star+ fill={darkMode ? "white" : "var(--ifm-link-color)"}+ height={200}+ width={200}+ points={5}+ innerRadius={innerRadius}+ outerRadius={outerRadius}+ />+ </AbsoluteFill>+ );+};diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsxindex 9935f1815d..df85976ff3 100644--- a/packages/docs/components/demos/index.tsx+++ b/packages/docs/components/demos/index.tsx@@ -10,6 +10,7 @@ import {ellipseDemo,noiseDemo,rectDemo,+ starDemo,triangleDemo,} from "./types";@@ -27,6 +28,7 @@ const demos: DemoType[] = [rectDemo,circleDemo,ellipseDemo,+ starDemo,];export const Demo: React.FC<{diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex 419348ef0d..9d36ba01e8 100644--- a/packages/docs/components/demos/types.ts+++ b/packages/docs/components/demos/types.ts@@ -2,6 +2,7 @@ import { CircleDemo } from "./Circle";import { EllipseDemo } from "./Ellipse";import { NoiseComp } from "./NoiseDemo";import { RectDemo } from "./Rect";+import { StarDemo } from "./Star";import { TriangleDemo } from "./Triangle";export type Option = {@@ -194,6 +195,36 @@ export const ellipseDemo: DemoType = {],};+export const starDemo: DemoType = {+ comp: StarDemo,+ compHeight: 720,+ compWidth: 1280,+ durationInFrames: 150,+ fps: 30,+ id: "star",+ autoPlay: true,+ options: [+ {+ default: 150,+ max: 400,+ step: 5,+ min: 1,+ type: "numeric",+ name: "innerRadius",+ optional: "no",+ },+ {+ default: 200,+ max: 400,+ step: 5,+ min: 1,+ type: "numeric",+ name: "outerRadius",+ optional: "no",+ },+ ],+};+export const noiseDemo: DemoType = {comp: NoiseComp,compHeight: 720,diff --git a/packages/docs/components/shapes/shapes-info.tsx b/packages/docs/components/shapes/shapes-info.tsxindex 3d821ecb98..8868452ff4 100644--- a/packages/docs/components/shapes/shapes-info.tsx+++ b/packages/docs/components/shapes/shapes-info.tsx@@ -2,6 +2,7 @@ import {makeCircle,makeEllipse,makeRect,+ makeStar,makeTriangle,} from "@remotion/shapes";import React from "react";@@ -83,6 +84,22 @@ export const shapeComponents: ShapeComponent[] = [},],},+ {+ shape: "Star",+ fn: makeStar,+ params: [+ {+ name: "width",+ type: "number",+ description: "The width of one triangle side.",+ },+ {+ name: "height",+ type: "number",+ description: "The width of one triangle side.",+ },+ ],+ },];const globalParams: Param[] = [diff --git a/packages/docs/docs/shapes/star.md b/packages/docs/docs/shapes/star.mdnew file mode 100644index 0000000000..d69c3bb451--- /dev/null+++ b/packages/docs/docs/shapes/star.md@@ -0,0 +1,50 @@+---+title: <Star />+crumb: "@remotion/shapes"+---++import {ShapeSeeAlso, ShapeOptions} from "../../components/shapes/shapes-info"++_Part of the [` @remotion/shapes`](/docs/shapes) package._++Renders an SVG element containing a star.++## Explorer++<Demo type="star"/>++## Example++```tsx twoslash title="src/Rect.tsx"+import { Star } from "@remotion/shapes";+import { AbsoluteFill } from "remotion";++export const MyComposition = () => {+ return (+ <AbsoluteFill+ style={{+ backgroundColor: "white",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <Star+ height={200}+ width={200}+ points={5}+ innerRadius={150}+ outerRadius={200}+ fill="red"+ />+ </AbsoluteFill>+ );+};+```++## Props++<ShapeOptions shape="star" all />++## See also++<ShapeSeeAlso shape="star"/>diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 5a28217aca..367b5ab5a1 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -298,6 +298,7 @@ module.exports = {"shapes/triangle","shapes/circle","shapes/ellipse",+ "shapes/star","shapes/make-rect","shapes/make-triangle","shapes/make-circle",diff --git a/packages/shapes/src/utils/star.ts b/packages/shapes/src/utils/star.tsindex a36e7a2d75..df1942db6c 100644--- a/packages/shapes/src/utils/star.ts+++ b/packages/shapes/src/utils/star.ts@@ -1,4 +1,4 @@-export type PolarToCartesianProps = {+type PolarToCartesianProps = {centerX: number;centerY: number;radius: number;@@ -6,7 +6,7 @@ export type PolarToCartesianProps = {outerRadius?: number;};-export const polarToCartesian = ({+const polarToCartesian = ({centerX,centerY,radius,@@ -19,67 +19,6 @@ export const polarToCartesian = ({};};-export type ArcProps = {- x: number;- y: number;- radius: number;- startAngle: number;- endAngle: number;- closeShape?: boolean;-};-export const arc = ({- x,- y,- radius,- startAngle,- endAngle,- closeShape,-}: ArcProps) => {- const fullCircle = endAngle - startAngle === 360;- const start = polarToCartesian({- centerX: x,- centerY: y,- radius,- angleInDegrees: endAngle - (fullCircle ? 0.01 : 0),- });- const end = polarToCartesian({- centerX: x,- centerY: y,- radius,- angleInDegrees: startAngle,- });- const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';-- const d = [- 'M',- start.x,- start.y,- 'A',- radius,- radius,- 0,- largeArcFlag,- 0,- end.x,- end.y,- closeShape && !fullCircle ? `L ${x} ${y} Z` : null,- fullCircle && !closeShape ? 'Z' : null,- ].join(' ');- return d;-};--export type PieProps = {- x: number;- y: number;- radius: number;- startAngle: number;- endAngle: number;-};--export const pie = ({x, y, radius, startAngle, endAngle}: PieProps) => {- return arc({x, y, radius, startAngle, endAngle});-};-export type StarProps = {centerX: number;centerY: number;