Skip to content

Commit 3e36d74

Browse files
committed
add shape splitting demo
1 parent 313d676 commit 3e36d74

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

demo/content.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {rand} from "../internal/rand";
2626
import {genFromOptions} from "../internal/gen";
2727
import {BlobOptions} from "../public/blobs";
2828
import {interpolateBetween, interpolateBetweenSmooth} from "../internal/animate/interpolate";
29+
import {divide} from "../internal/animate/prepare";
30+
import blobs from "../public/legacy";
2931

3032
const makePoly = (pointCount: number, radius: number, center: Coord): Point[] => {
3133
const angle = (2 * Math.PI) / pointCount;
@@ -578,5 +580,42 @@ addCanvas(
578580
);
579581
});
580582
},
581-
() => {},
583+
(ctx, width, height, animate) => {
584+
const period = (Math.PI + Math.E) * 1000;
585+
const center: Coord = {x: width * 0.5, y: height * 0.5};
586+
const maxExtraPoints = 4;
587+
const {pt} = sizes();
588+
589+
const blob = centeredBlob(
590+
{
591+
extraPoints: 0,
592+
randomness: 6,
593+
seed: "flip",
594+
size: height * 0.9,
595+
},
596+
center,
597+
);
598+
599+
animate((frameTime) => {
600+
const percentage = mod(frameTime, period) / period;
601+
const extraPoints = Math.floor(percentage * (maxExtraPoints + 1));
602+
drawClosed(ctx, divide(extraPoints + blob.length, blob), true);
603+
604+
forPoints(blob, ({curr}) => {
605+
ctx.beginPath();
606+
ctx.arc(curr.x, curr.y, pt * 6, 0, 2 * Math.PI);
607+
608+
tempStyles(
609+
ctx,
610+
() => {
611+
ctx.strokeStyle = colors.secondary;
612+
ctx.lineWidth = pt;
613+
},
614+
() => {
615+
ctx.stroke();
616+
},
617+
);
618+
});
619+
});
620+
},
582621
);

0 commit comments

Comments
 (0)