Skip to content

🎥 Make videos programmatically with React

works

Jonny Burgera1fca9c36ae5
diff --git a/packages/shapes/src/utils/instructions.ts b/packages/shapes/src/utils/instructions.ts
index 8340f85249..5227d8f894 100644
--- a/packages/shapes/src/utils/instructions.ts
+++ b/packages/shapes/src/utils/instructions.ts
@@ -28,6 +28,16 @@ export type Instruction =
x: number;
y: number;
}
+ | {
+ type: 'A';
+ rx: number;
+ ry: number;
+ xAxisRotation: number;
+ largeArcFlag: boolean;
+ sweepFlag: boolean;
+ x: number;
+ y: number;
+ }
| {
type: 'z';
};
@@ -57,6 +67,14 @@ export const serializeInstruction = (instruction: Instruction) => {
)} ${instruction.x} ${instruction.y}`;
}
+ if (instruction.type === 'A') {
+ return `A ${instruction.rx} ${instruction.ry} ${
+ instruction.xAxisRotation
+ } ${Number(instruction.largeArcFlag)} ${Number(
+ instruction.sweepFlag ? 1 : 0
+ )} ${instruction.x} ${instruction.y}`;
+ }
+
if (instruction.type === 'z') {
return 'z';
}
diff --git a/packages/shapes/src/utils/make-pie.ts b/packages/shapes/src/utils/make-pie.ts
index 4f87809ff7..d35338d7af 100644
--- a/packages/shapes/src/utils/make-pie.ts
+++ b/packages/shapes/src/utils/make-pie.ts
@@ -7,6 +7,11 @@ export type MakePieProps = {
};
export const makePie = ({fillAmount, radius}: MakePieProps) => {
+ const endAngleX =
+ Math.cos(-fillAmount * Math.PI * 2 + Math.PI) * radius + radius;
+ const endAngleY =
+ Math.sin(-fillAmount * Math.PI * 2 + Math.PI) * radius + radius;
+
const instructions: Instruction[] = [
{
type: 'M',
@@ -14,25 +19,32 @@ export const makePie = ({fillAmount, radius}: MakePieProps) => {
y: radius,
},
{
- type: 'a',
+ type: 'A',
rx: radius,
ry: radius,
xAxisRotation: 0,
- largeArcFlag: true,
+ largeArcFlag: false,
sweepFlag: false,
- x: radius * 2,
- y: 0,
+ x: fillAmount <= 0.5 ? endAngleX : radius * 2,
+ y: fillAmount <= 0.5 ? endAngleY : radius,
},
fillAmount > 0.5
? {
- type: 'a',
+ type: 'A',
rx: radius,
ry: radius,
xAxisRotation: 0,
- largeArcFlag: true,
+ largeArcFlag: false,
sweepFlag: false,
- x: -radius * 2,
- y: 0,
+ x: endAngleX,
+ y: endAngleY,
+ }
+ : null,
+ fillAmount > 0 && fillAmount < 1
+ ? {
+ type: 'L',
+ x: radius,
+ y: radius,
}
: null,
{