Skip to content

Commit 70b0d31

Browse files
authored
Merge pull request #103 from code-dot-org/ease-fish-movement-animations
Ease fish movement animations
2 parents 0e620e8 + a80c925 commit 70b0d31

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/demo/renderer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ const finishMovement = () => {
162162

163163
// Calculate the screen's current X offset.
164164
const getOffsetForTime = (t, totalFish) => {
165+
// Normalize the fish movement amount from 0 to 1.
166+
let amount = t / moveTime;
167+
168+
// Apply an S-curve to that amount.
169+
amount = amount - Math.sin(amount*2*Math.PI) / (2*Math.PI);
170+
165171
return (
166172
constants.fishCanvasWidth * totalFish -
167173
constants.canvasWidth / 2 +
168174
constants.fishCanvasWidth / 2 -
169-
Math.round((t * constants.fishCanvasWidth) / moveTime)
175+
Math.round(amount * constants.fishCanvasWidth)
170176
);
171177
};
172178

0 commit comments

Comments
 (0)