Skip to content

Commit f5bd3b5

Browse files
committed
fix animation breakage when transitioning with more than one frame
1 parent 5acb158 commit f5bd3b5

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

internal/animate/interpolate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const interpolateAngle = (percentage: number, a: number, b: number): number => {
2020
// Interpolates linearly between a and b. Can only interpolate between point lists that have the
2121
// same number of points. Easing effects can be applied to the percentage given to this function.
2222
// Percentages outside the 0-1 range are supported.
23+
// TODO handle length should continue animating?
2324
export const interpolateBetween = (percentage: number, a: Point[], b: Point[]): Point[] => {
2425
if (a.length !== b.length) throw new Error("must have equal number of points");
2526

internal/animate/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const renderFramesAt = (input: RenderInput): RenderOutput => {
6767
let startKeyframe = currentFrames[0];
6868
let endKeyframe = currentFrames[1];
6969
for (let i = 2; i < currentFrames.length; i++) {
70-
if (endKeyframe.timestamp < input.timestamp) break;
70+
if (endKeyframe.timestamp > input.timestamp) break;
7171
startKeyframe = currentFrames[i - 1];
7272
endKeyframe = currentFrames[i];
7373
}

internal/animate/testing/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
display: flex;
1919
flex-direction: column;
2020
}
21+
22+
#interact {
23+
margin-top: 20px;
24+
padding: 10px;
25+
}
2126
</style>
2227
</head>
2328

internal/animate/testing/script.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -262,52 +262,45 @@ const loopBetween = (percentage: number, a: Point[], b: Point[]): Point[] => {
262262
const animation = blobs2Animate.canvasPath();
263263

264264
const loopAnimation = () => {
265-
console.log("LOOP");
266-
267-
animation.transition(
268-
{
269-
duration: 2000,
270-
blobOptions: {
271-
extraPoints: 3,
272-
randomness: 3,
273-
seed: "blob1",
274-
size: 200,
275-
},
276-
},
277-
{
278-
duration: 2000,
279-
callback: loopAnimation,
280-
blobOptions: {
281-
extraPoints: 3,
282-
randomness: 3,
283-
seed: "blob2",
284-
size: 200,
285-
},
265+
animation.transition({
266+
duration: 2000 + 1000 * Math.random(),
267+
callback: loopAnimation,
268+
timingFunction: "easeInOut",
269+
blobOptions: {
270+
extraPoints: 3,
271+
randomness: 4,
272+
seed: Math.random(),
273+
size: 200,
286274
},
287-
);
275+
});
288276
};
289277

290278
animation.transition({
291-
duration: 100,
279+
duration: 0,
292280
callback: loopAnimation,
293281
blobOptions: {
294-
extraPoints: 3,
295-
randomness: 3,
296-
seed: "start",
282+
extraPoints: 1,
283+
randomness: 0,
284+
seed: 0,
297285
size: 200,
298286
},
299287
});
300288

301289
interact.onclick = () => {
302290
animation.transition({
303-
duration: 1000,
291+
duration: 400,
304292
callback: loopAnimation,
293+
timingFunction: "elasticIn0",
305294
blobOptions: {
306295
extraPoints: 3,
307-
randomness: 7,
308-
seed: "onClick",
309-
size: 200,
296+
randomness: 8,
297+
seed: Math.random(),
298+
size: 180,
310299
},
300+
canvasOptions: {
301+
offsetX: 10,
302+
offsetY: 10,
303+
}
311304
});
312305
};
313306

@@ -329,11 +322,12 @@ interact.onclick = () => {
329322
testPrepPointsD(percentage);
330323
testPrepLetters(percentage);
331324

325+
ctx.fill(animation.renderFrame());
326+
332327
percentage += animationSpeed / 1000;
333328
percentage = mod(percentage, 1);
334329
if (animationSpeed > 0) requestAnimationFrame(renderFrame);
335330

336-
ctx.fill(animation.renderFrame());
337331
};
338332
renderFrame();
339333
})();

0 commit comments

Comments
 (0)