From a80c925543e1d65648c99f26f5e9e7171a8d3a2f Mon Sep 17 00:00:00 2001 From: Brendan Reville Date: Fri, 25 Oct 2019 14:00:21 -0700 Subject: [PATCH] Ease fish movement animations --- src/demo/renderer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/demo/renderer.js b/src/demo/renderer.js index 384b2d86..c157e5c7 100644 --- a/src/demo/renderer.js +++ b/src/demo/renderer.js @@ -162,11 +162,17 @@ const finishMovement = () => { // Calculate the screen's current X offset. const getOffsetForTime = (t, totalFish) => { + // Normalize the fish movement amount from 0 to 1. + let amount = t / moveTime; + + // Apply an S-curve to that amount. + amount = amount - Math.sin(amount*2*Math.PI) / (2*Math.PI); + return ( constants.fishCanvasWidth * totalFish - constants.canvasWidth / 2 + constants.fishCanvasWidth / 2 - - Math.round((t * constants.fishCanvasWidth) / moveTime) + Math.round(amount * constants.fishCanvasWidth) ); };