Skip to content

Commit 4ecbee6

Browse files
committed
move shape preping to own helper
1 parent 71cb9cc commit 4ecbee6

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

animate/index.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ const interpolateBetweenLoop = (percentage: number, a: Point[], b: Point[]): Poi
382382
}
383383
};
384384

385+
const prepShapes = (a: Point[], b: Point[]): [Point[], Point[]] => {
386+
const points = Math.max(a.length, b.length);
387+
const aNorm = divideShape(points, a);
388+
const bNorm = divideShape(points, b);
389+
const bOpt = optimizeOrder(aNorm, bNorm);
390+
const bFix = fixAngles(aNorm, bOpt);
391+
return [aNorm, bFix];
392+
};
393+
385394
const testSplitAt = (percentage: number) => {
386395
let points: Point[] = [
387396
point(0.15, 0.15, 135, 0.1, 315, 0.2),
@@ -452,35 +461,21 @@ const testInterpolateBetween = (percentage: number) => {
452461
renderShape(interpolateBetweenLoop(percentage, a, b));
453462
};
454463

455-
const testBlobMorph = (percentage: number) => {
464+
const testPrepShapesA = (percentage: number) => {
456465
const a = genBlob("a", 0.6, 0.6, 0.3, {x: 0.5, y: 0.2});
457466
const b = genBlob("b", 1, 0.6, 0.3, {x: 0.5, y: 0.2});
458-
459-
const points = Math.max(a.length, b.length);
460-
const aNorm = divideShape(points, a);
461-
const bNorm = divideShape(points, b);
462-
const bOpt = optimizeOrder(aNorm, bNorm);
463-
const bFix = fixAngles(aNorm, bOpt);
464-
465-
renderShape(interpolateBetweenLoop(percentage, aNorm, bFix));
467+
renderShape(interpolateBetweenLoop(percentage, ...prepShapes(a, b)));
466468
};
467469

468-
const testShapeMorph = (percentage: number) => {
470+
const testPrepShapesB = (percentage: number) => {
469471
const a = genBlob("a", 0.6, 0.6, 0.3, {x: 0.5, y: 0.5});
470472
const b: Point[] = [
471473
point(0.55, 0.5, 0, 0, 0, 0),
472474
point(0.75, 0.5, 0, 0, 0, 0),
473475
point(0.75, 0.7, 0, 0, 0, 0),
474476
point(0.55, 0.7, 0, 0, 0, 0),
475477
];
476-
477-
const points = Math.max(a.length, b.length);
478-
const aNorm = divideShape(points, a);
479-
const bNorm = divideShape(points, b);
480-
const bOpt = optimizeOrder(aNorm, bNorm);
481-
const bFix = fixAngles(aNorm, bOpt);
482-
483-
renderShape(interpolateBetweenLoop(percentage, aNorm, bFix));
478+
renderShape(interpolateBetweenLoop(percentage, ...prepShapes(a, b)));
484479
};
485480

486481
const genBlob = (
@@ -533,8 +528,8 @@ const genBlob = (
533528
testSplitBy();
534529
testDivideShape();
535530
testInterpolateBetween(percentage);
536-
testBlobMorph(percentage);
537-
testShapeMorph(percentage);
531+
testPrepShapesA(percentage);
532+
testPrepShapesB(percentage);
538533

539534
percentage += animationSpeed / 1000;
540535
percentage %= 1;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "npm run clean && rollup -c rollup.config.ts",
1313
"clean": "trash '**/*.js' '**/*.js.map' '**/*.d.ts' '!**/node_modules/**/*'",
1414
"fmt": "prettier --list-different --write --ignore-path .gitignore '**/*.{js,ts}'",
15-
"dev:animate": "parcel animate/index.html",
15+
"dev:animate": "parcel animate/index.html --open",
1616
"test": "jest"
1717
},
1818
"devDependencies": {

0 commit comments

Comments
 (0)