Skip to content

Commit 8bca5b8

Browse files
committed
generate public bundle for animation api
1 parent f5bd3b5 commit 8bca5b8

File tree

3 files changed

+82
-37
lines changed

3 files changed

+82
-37
lines changed

internal/animate/testing/script.ts

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -259,54 +259,94 @@ const loopBetween = (percentage: number, a: Point[], b: Point[]): Point[] => {
259259
}
260260
};
261261

262-
const animation = blobs2Animate.canvasPath();
262+
const genAnimation = (speed: number): blobs2Animate.CanvasAnimation => {
263+
const animation = blobs2Animate.canvasPath();
264+
265+
const loopAnimation = () => {
266+
animation.transition(
267+
{
268+
duration: speed,
269+
delay: speed,
270+
timingFunction: "easeInOut",
271+
blobOptions: {
272+
extraPoints: 3,
273+
randomness: 4,
274+
seed: Math.random(),
275+
size: 200,
276+
},
277+
},
278+
{
279+
duration: speed,
280+
timingFunction: "easeInOut",
281+
blobOptions: {
282+
extraPoints: 3,
283+
randomness: 4,
284+
seed: Math.random(),
285+
size: 200,
286+
},
287+
},
288+
{
289+
duration: speed,
290+
delay: speed,
291+
timingFunction: "easeInOut",
292+
blobOptions: {
293+
extraPoints: 3,
294+
randomness: 4,
295+
seed: Math.random(),
296+
size: 200,
297+
},
298+
},
299+
{
300+
duration: speed,
301+
callback: loopAnimation,
302+
timingFunction: "easeInOut",
303+
blobOptions: {
304+
extraPoints: 39,
305+
randomness: 2,
306+
seed: Math.random(),
307+
size: 200,
308+
},
309+
},
310+
);
311+
};
263312

264-
const loopAnimation = () => {
265313
animation.transition({
266-
duration: 2000 + 1000 * Math.random(),
314+
duration: 0,
267315
callback: loopAnimation,
268-
timingFunction: "easeInOut",
269316
blobOptions: {
270-
extraPoints: 3,
271-
randomness: 4,
272-
seed: Math.random(),
317+
extraPoints: 1,
318+
randomness: 0,
319+
seed: 0,
273320
size: 200,
274321
},
275322
});
276-
};
277323

278-
animation.transition({
279-
duration: 0,
280-
callback: loopAnimation,
281-
blobOptions: {
282-
extraPoints: 1,
283-
randomness: 0,
284-
seed: 0,
285-
size: 200,
286-
},
287-
});
288-
289-
interact.onclick = () => {
290-
animation.transition({
291-
duration: 400,
292-
callback: loopAnimation,
293-
timingFunction: "elasticIn0",
294-
blobOptions: {
295-
extraPoints: 3,
296-
randomness: 8,
297-
seed: Math.random(),
298-
size: 180,
299-
},
300-
canvasOptions: {
301-
offsetX: 10,
302-
offsetY: 10,
303-
}
304-
});
324+
interact.onclick = () => {
325+
animation.transition({
326+
duration: 400,
327+
callback: loopAnimation,
328+
timingFunction: "elasticIn0",
329+
blobOptions: {
330+
extraPoints: 3,
331+
randomness: 8,
332+
seed: Math.random(),
333+
size: 180,
334+
},
335+
canvasOptions: {
336+
offsetX: 10,
337+
offsetY: 10,
338+
},
339+
});
340+
};
341+
342+
return animation;
305343
};
306344

307345
(() => {
308346
let percentage = animationStart;
309347

348+
const animation = genAnimation(1000);
349+
310350
const renderFrame = () => {
311351
clear(ctx);
312352

@@ -327,7 +367,6 @@ interact.onclick = () => {
327367
percentage += animationSpeed / 1000;
328368
percentage = mod(percentage, 1);
329369
if (animationSpeed > 0) requestAnimationFrame(renderFrame);
330-
331370
};
332371
renderFrame();
333372
})();

internal/animate/timing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export const timingFunctions = {
4444
elasticOut3: elasticOut(0.05),
4545
};
4646

47-
// Type assertion.
47+
// @ts-ignore: Type assertion.
4848
const _: Record<string, TimingFunc> = timingFunctions;

rollup.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const bundles = [
2121
types: "public/blobs.d.ts",
2222
output: "v2",
2323
},
24+
{
25+
name: "blobs2Animate",
26+
entry: "public/animate.ts",
27+
types: "public/animate.d.ts",
28+
output: "v2/animate",
29+
},
2430
];
2531

2632
export default bundles.map((bundle) => ({

0 commit comments

Comments
 (0)