Skip to content

Commit bdb8c9b

Browse files
committed
add points to blob on each consecutive click
1 parent fe9b7a5 commit bdb8c9b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

demo/example.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,39 @@ const renderFrame = () => {
3434
};
3535
requestAnimationFrame(renderFrame);
3636

37+
// Extra points that increases when blob gets clicked.
38+
let extraPoints = 0;
39+
3740
// Generate a keyframe with overridable default values.
38-
const genFrame = (overrides: Partial<CanvasKeyframe> = {}): CanvasKeyframe => ({
39-
duration: 4000,
40-
timingFunction: "ease",
41-
callback: loopAnimation,
42-
blobOptions: {
43-
extraPoints: 3,
41+
const genFrame = (overrides: any = {}): CanvasKeyframe => {
42+
const blobOptions = {
43+
extraPoints: 3 + extraPoints,
4444
randomness: 4,
4545
seed: Math.random(),
4646
size,
47-
},
48-
...overrides,
49-
});
47+
...overrides.blobOptions,
48+
};
49+
return {
50+
duration: 4000,
51+
timingFunction: "ease",
52+
callback: loopAnimation,
53+
...overrides,
54+
blobOptions,
55+
};
56+
};
5057

5158
// Callback for every frame which starts transition to a new frame.
52-
const loopAnimation = (): void => animation.transition(genFrame());
59+
const loopAnimation = (): void => {
60+
extraPoints = 0;
61+
animation.transition(genFrame());
62+
};
5363

5464
// Quickly animate to a new frame when canvas is clicked.
5565
canvas.onclick = () => {
56-
animation.transition(genFrame({duration: 400, timingFunction: "elasticEnd0"}));
66+
extraPoints++;
67+
animation.transition(
68+
genFrame({duration: 400, timingFunction: "elasticEnd0", blobOptions: {extraPoints}}),
69+
);
5770
};
5871

5972
// Immediately show a new frame.

0 commit comments

Comments
 (0)