Skip to content

Commit 3329ac1

Browse files
committed
pause shift animation after each shift
1 parent dbd1fca commit 3329ac1

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

demo/content.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ addCanvas(2, (ctx, width, height, animate) => {
434434
addCanvas(
435435
1.3,
436436
(ctx, width, height, animate) => {
437-
const period = Math.PI ** Math.E * 1000;
437+
const period = (Math.E / Math.PI) * 1000;
438438
const center: Coord = {x: width * 0.5, y: height * 0.5};
439439

440440
const blob = centeredBlob(
@@ -447,18 +447,20 @@ addCanvas(
447447
center,
448448
);
449449

450+
const shiftedBlob = shift(1, blob);
451+
452+
let prev = 0;
453+
let count = 0;
450454
animate((frameTime) => {
451455
const animationTime = mod(frameTime, period);
452-
const totalShifts = blob.length;
453-
const localPeriod = period / totalShifts;
456+
const percentage = timingFunctions.ease(mod(animationTime, period) / period);
454457

455-
const shiftNumber = Math.floor((animationTime / period) * totalShifts);
456-
const localPercentage = timingFunctions.ease(
457-
mod(animationTime, localPeriod) / localPeriod,
458-
);
459-
460-
const prevBlob = shift(shiftNumber - 1, blob);
461-
const currentBlob = shift(shiftNumber, blob);
458+
// Count animation loops.
459+
if (percentage < prev) {
460+
count++;
461+
console.log(count);
462+
}
463+
prev = percentage;
462464

463465
// Draw lines points are travelling.
464466
tempStyles(
@@ -475,11 +477,12 @@ addCanvas(
475477
},
476478
);
477479

478-
drawClosed(
479-
ctx,
480-
interpolateBetweenSmooth(2, localPercentage, prevBlob, currentBlob),
481-
true,
482-
);
480+
// Pause in-place every other animation loop.
481+
if (count % 2 === 0) {
482+
drawClosed(ctx, interpolateBetweenSmooth(2, percentage, blob, shiftedBlob), true);
483+
} else {
484+
drawClosed(ctx, blob, true);
485+
}
483486
});
484487

485488
return `Points cannot be swapped without resulting in a different shape. However, a likely

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
border: 1px solid #eee;
8383
border-radius: 0.5rem;
8484
display: flex;
85-
margin-bottom: 3rem;
85+
margin: 3rem 0;
8686
max-width: 1000px;
8787
width: 100%;
8888
}

0 commit comments

Comments
 (0)