From 16da7fb310198851c2e4b02abedfb24979287242 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 7 Jan 2017 18:26:02 -0400 Subject: Initial commit --- util/smoothen.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 util/smoothen.js (limited to 'util/smoothen.js') diff --git a/util/smoothen.js b/util/smoothen.js new file mode 100644 index 0000000..55ba23c --- /dev/null +++ b/util/smoothen.js @@ -0,0 +1,16 @@ +module.exports = function(tx, x, divisor) { + // Smoothly transitions givens X to TX using a given divisor. Rounds the + // amount moved. + + const move = (tx - x) / divisor + + if (move > 0.5) { + return x + Math.ceil(move) + } else if (move < -0.5) { + return x + Math.floor(move) + } else if (tx > 0) { + return Math.ceil(tx) + } else { + return Math.floor(tx) + } +} -- cgit 1.3.0-6-gf8a5