Skip to content

Commit 873ab94

Browse files
committed
add labels to shape optimization demos
1 parent 3e36d74 commit 873ab94

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

demo/content.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,48 @@ addCanvas(
519519

520520
addCanvas(
521521
1.3,
522+
(ctx, width, height, animate) => {
523+
const period = Math.PI * 1000;
524+
const center: Coord = {x: width * 0.5, y: height * 0.5};
525+
const maxExtraPoints = 4;
526+
const {pt} = sizes();
527+
528+
const blob = centeredBlob(
529+
{
530+
extraPoints: 0,
531+
randomness: 6,
532+
seed: "flip",
533+
size: height * 0.9,
534+
},
535+
center,
536+
);
537+
538+
animate((frameTime) => {
539+
const percentage = mod(frameTime, period) / period;
540+
const extraPoints = Math.floor(percentage * (maxExtraPoints + 1));
541+
drawClosed(ctx, divide(extraPoints + blob.length, blob), true);
542+
543+
forPoints(blob, ({curr}) => {
544+
ctx.beginPath();
545+
ctx.arc(curr.x, curr.y, pt * 6, 0, 2 * Math.PI);
546+
547+
tempStyles(
548+
ctx,
549+
() => {
550+
ctx.strokeStyle = colors.secondary;
551+
ctx.lineWidth = pt;
552+
},
553+
() => {
554+
ctx.stroke();
555+
},
556+
);
557+
});
558+
});
559+
560+
return `Points are added to the shape with the least until the shapes match. These new
561+
points are as evenly distributed as possible. It is very rare to be able to remove
562+
points from a shape without changing it.`;
563+
},
522564
(ctx, width, height, animate) => {
523565
const period = Math.PI ** Math.E * 1000;
524566
const start = point(width * 0.1, height * 0.6, 0, 0, -45, width * 0.5);
@@ -579,43 +621,8 @@ addCanvas(
579621
() => drawPoint(ctx, d.d0, 2),
580622
);
581623
});
582-
},
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();
588624

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-
});
625+
return `Curve splitting uses the innermost line from the above curve drawing demo and makes
626+
either side of the final point the handles.`;
620627
},
621628
);

0 commit comments

Comments
 (0)