Skip to content

🎥 Make videos programmatically with React

implemented basic star

Alex Fernandez26a1757accfe
diff --git a/packages/example/src/Shapes/StarTest.tsx b/packages/example/src/Shapes/StarTest.tsx
new file mode 100644
index 0000000000..ed20c6763d
--- /dev/null
+++ b/packages/example/src/Shapes/StarTest.tsx
@@ -0,0 +1,26 @@
+import {Star} from '@remotion/shapes';
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+const StarTest: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ display: 'flex',
+ justifyContent: 'center',
+ alignContent: 'center',
+ alignItems: 'center',
+ flexDirection: 'row',
+ }}
+ >
+ <Star
+ width={200}
+ height={200}
+ points={5}
+ innerRadius={80}
+ outerRadius={200}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export default StarTest;
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index a1e0f3dd40..eda1886cb5 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -21,6 +21,7 @@ import {Scripts} from './Scripts';
import CircleTest from './Shapes/CircleTest';
import EllipseTest from './Shapes/EllipseTest';
import RectTest from './Shapes/RectTest';
+import StarTest from './Shapes/StarTest';
import TriangleTest from './Shapes/TriangleTest';
import {SkipZeroFrame} from './SkipZeroFrame';
import {BaseSpring, SpringWithDuration} from './Spring/base-spring';
@@ -601,6 +602,14 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={150}
/>
+ <Composition
+ id="star-test"
+ component={StarTest}
+ width={1200}
+ height={630}
+ fps={30}
+ durationInFrames={150}
+ />
</Folder>
</>
);
diff --git a/packages/shapes/src/components/star.tsx b/packages/shapes/src/components/star.tsx
new file mode 100644
index 0000000000..d71a85c3db
--- /dev/null
+++ b/packages/shapes/src/components/star.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import type {MakeStarProps} from '../utils/make-star';
+import {makeStar} from '../utils/make-star';
+import type {AllShapesProps} from './render-svg';
+import {RenderSvg} from './render-svg';
+
+export type StarProps = MakeStarProps & AllShapesProps;
+
+export const Star: React.FC<StarProps> = ({
+ width,
+ height,
+ innerRadius,
+ outerRadius,
+ points,
+ ...props
+}) => {
+ return (
+ <RenderSvg
+ {...makeStar({height, width, innerRadius, outerRadius, points})}
+ {...props}
+ />
+ );
+};
diff --git a/packages/shapes/src/index.ts b/packages/shapes/src/index.ts
index 38897c6709..648e34b905 100644
--- a/packages/shapes/src/index.ts
+++ b/packages/shapes/src/index.ts
@@ -1,9 +1,11 @@
export {Circle, CircleProps} from './components/circle';
export {Ellipse, EllipseProps} from './components/ellipse';
export {Rect, RectProps} from './components/rect';
+export {Star, StarProps} from './components/star';
export {Triangle, TriangleProps} from './components/triangle';
export {Instruction} from './utils/instructions';
export {makeCircle, MakeCircleProps} from './utils/make-circle';
export {makeEllipse, MakeEllipseOptions} from './utils/make-ellipse';
export {makeRect, MakeRectOptions} from './utils/make-rect';
+export {makeStar, MakeStarProps} from './utils/make-star';
export {makeTriangle, MakeTriangleProps} from './utils/make-triangle';
diff --git a/packages/shapes/src/utils/make-star.ts b/packages/shapes/src/utils/make-star.ts
index fc4b4c68af..9b428344f5 100644
--- a/packages/shapes/src/utils/make-star.ts
+++ b/packages/shapes/src/utils/make-star.ts
@@ -18,8 +18,8 @@ export const makeStar = ({
innerRadius,
outerRadius,
}: MakeStarProps): ShapeInfo => {
- const centerX = width;
- const centerY = height;
+ const centerX = width / 2;
+ const centerY = height / 2;
const starPath = star({
centerX,
@@ -34,5 +34,6 @@ export const makeStar = ({
width,
height,
transformOrigin: `${centerX} ${centerY}`,
+ instructions: [],
};
};
diff --git a/packages/shapes/src/utils/star.ts b/packages/shapes/src/utils/star.ts
index e382a8cb64..a36e7a2d75 100644
--- a/packages/shapes/src/utils/star.ts
+++ b/packages/shapes/src/utils/star.ts
@@ -96,7 +96,7 @@ export const star = ({
outerRadius,
}: StarProps): string => {
const degreeIncrement = 360 / (points * 2);
- const d = new Array(points * 2).fill('foo').map((_p, i) => {
+ const d = new Array(points * 2).fill('true').map((_p, i) => {
const radius = i % 2 === 0 ? outerRadius : innerRadius;
const degrees = degreeIncrement * i;
const point = polarToCartesian({