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 378ae27

Browse files
committed
add animation to shapes demo
1 parent af646d4 commit 378ae27

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

‎demo/content.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {BlobOptions} from "../public/blobs";
3030
import {interpolateBetween, interpolateBetweenSmooth} from "../internal/animate/interpolate";
3131
import {divide} from "../internal/animate/prepare";
3232
import {statefulAnimationGenerator} from "../internal/animate/state";
33-
import {CanvasCustomKeyframe, CanvasKeyframe, wigglePreset} from "../public/animate";
33+
import {CanvasCustomKeyframe, CanvasKeyframe, canvasPath,wigglePreset} from "../public/animate";
3434

3535
const makePoly = (pointCount: number, radius: number, center: Coord): Point[] => {
3636
const angle = (2 * Math.PI) / pointCount;
@@ -848,7 +848,7 @@ addCanvas(
848848
been reached. However if the animation is interrupted during interpolation there is no
849849
opportunity to clean up the extra points.`;
850850
},
851-
(ctx, width, height) => {
851+
(ctx, width, height,animate) => {
852852
const center: Coord = {x: width * 0.5, y: height * 0.5};
853853
const size = Math.min(width, height) * 0.8;
854854

@@ -870,7 +870,23 @@ addCanvas(
870870
return points;
871871
};
872872

873-
drawClosed(ctx, smoothBlob(drawStar(12, size, size * 0.9)), true);
873+
const pointy = drawStar(8, size, size * 0.4);
874+
const wobblyGerm = smoothBlob(drawStar(12, size, size * 0.9));
875+
const shapes = [pointy, wobblyGerm];
876+
877+
const animation = canvasPath();
878+
animation.transition({
879+
points: pointy,
880+
duration: 1000,
881+
callback: () => animation.transition({
882+
points: wobblyGerm,
883+
duration: 4000,
884+
}),
885+
});
886+
887+
animate(() => drawClosed(ctx, animation.renderPoints(), true));
888+
889+
drawClosed(ctx, pointy, true);
874890

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

‎public/animate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface CanvasCustomKeyframe extends Keyframe {
5858
export interface Animation {
5959
// Renders the current state of the animation.
6060
renderFrame: () => Path2D;
61+
// Renders the current state of the animation as points.
62+
renderPoints: () => Point[];
6163
// Immediately begin animating through the given keyframes.
6264
// Non-rendered keyframes from previous transitions are cancelled.
6365
transition: (...keyframes: (CanvasKeyframe | CanvasCustomKeyframe)[]) => void;

0 commit comments

Comments
(0)

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