Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3ec7c8f

Browse files
committed
add more shapes and animate between them
1 parent 5c7f3c0 commit 3ec7c8f

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

‎demo/content.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -870,24 +870,50 @@ addCanvas(
870870
return points;
871871
};
872872

873-
const pointy = drawStar(8, size, size * 0.4);
874-
const wobblyGerm = smoothBlob(drawStar(12, size, size * 0.9));
875-
const shapes = [pointy, wobblyGerm];
873+
const drawPolygon = (sides: number, od: number): Point[] => {
874+
const angle = (Math.PI * 2) / sides;
875+
const points: Point[] = [];
876+
for (let i = 0; i < sides; i++) {
877+
const pointX = Math.sin(i * angle);
878+
const pointY = Math.cos(i * angle);
879+
const distanceMultiplier = od / 2;
880+
points.push({
881+
x: center.x + pointX * distanceMultiplier,
882+
y: center.y + pointY * distanceMultiplier,
883+
handleIn: {angle: 0, length: 0},
884+
handleOut: {angle: 0, length: 0},
885+
});
886+
}
887+
return points;
888+
};
889+
890+
const shapes = [
891+
drawStar(8, size, size * 0.7),
892+
smoothBlob(drawPolygon(3, size)),
893+
smoothBlob(drawStar(10, size, size * 0.9)),
894+
drawPolygon(4, size),
895+
smoothBlob(drawStar(3, size, size * 0.6)),
896+
];
876897

877898
const animation = canvasPath();
899+
const genFrame = (index: number) => () => {
900+
animation.transition({
901+
points: shapes[index % shapes.length],
902+
duration: 3000,
903+
delay: 1000,
904+
timingFunction: "ease",
905+
callback: genFrame(index + 1),
906+
});
907+
};
878908
animation.transition({
879-
points: pointy,
880-
duration: 1000,
881-
callback: () =>
882-
animation.transition({
883-
points: wobblyGerm,
884-
duration: 4000,
885-
}),
909+
points: shapes[0],
910+
duration: 0,
911+
callback: genFrame(1),
886912
});
887913

888-
animate(() => drawClosed(ctx,animation.renderPoints(),true));
889-
890-
drawClosed(ctx,pointy,true);
914+
animate(() => {
915+
drawClosed(ctx,animation.renderPoints(),true);
916+
});
891917

892918
return `Putting all these pieces together, the blob transition library can also be used to
893919
tween between non-blob shapes. The more detail a shape has, the more unconvincing the

‎public/animate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const wigglePreset = (
162162
});
163163

164164
if (count < transitionFrameCount) {
165-
// Create intermediate frame between the current state and the
165+
// Create intermediate frame between the current state and the
166166
// moving noiseBlob target.
167167
const [preparedStartPoints, preparedEndPoints] = prepare(
168168
transitionStartFrame,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /