🎥 Make videos programmatically with React
feat: initial star
Alex Fernandez323e6cee8a09
diff --git a/packages/shapes/src/utils/make-star.ts b/packages/shapes/src/utils/make-star.tsnew file mode 100644index 0000000000..fc4b4c68af--- /dev/null+++ b/packages/shapes/src/utils/make-star.ts@@ -0,0 +1,38 @@+// Copied from https://stackblitz.com/edit/svg-star-generator?file=index.js++import type {ShapeInfo} from './shape-info';+import {star} from './star';++export type MakeStarProps = {+ width: number;+ height: number;+ points: number;+ innerRadius: number;+ outerRadius: number;+};++export const makeStar = ({+ width,+ height,+ points,+ innerRadius,+ outerRadius,+}: MakeStarProps): ShapeInfo => {+ const centerX = width;+ const centerY = height;++ const starPath = star({+ centerX,+ centerY,+ points,+ innerRadius,+ outerRadius,+ });++ return {+ path: starPath,+ width,+ height,+ transformOrigin: `${centerX} ${centerY}`,+ };+};diff --git a/packages/shapes/src/utils/star.ts b/packages/shapes/src/utils/star.tsnew file mode 100644index 0000000000..e382a8cb64--- /dev/null+++ b/packages/shapes/src/utils/star.ts@@ -0,0 +1,111 @@+export type PolarToCartesianProps = {+ centerX: number;+ centerY: number;+ radius: number;+ angleInDegrees: number;+ outerRadius?: number;+};++export const polarToCartesian = ({+ centerX,+ centerY,+ radius,+ angleInDegrees,+}: PolarToCartesianProps) => {+ const angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;+ return {+ x: centerX + radius * Math.cos(angleInRadians),+ y: centerY + radius * Math.sin(angleInRadians),+ };+};++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;+ points: number;+ innerRadius: number;+ outerRadius: number;+};++export const star = ({+ centerX,+ centerY,+ points,+ innerRadius,+ outerRadius,+}: StarProps): string => {+ const degreeIncrement = 360 / (points * 2);+ const d = new Array(points * 2).fill('foo').map((_p, i) => {+ const radius = i % 2 === 0 ? outerRadius : innerRadius;+ const degrees = degreeIncrement * i;+ const point = polarToCartesian({+ centerX,+ centerY,+ radius,+ angleInDegrees: degrees,+ });+ return `${point.x},${point.y}`;+ });+ return `M${d}Z`;+};