smoothen.js 383 B

1234567891011121314151617
  1. export default function smoothen(tx, x, divisor) {
  2. // Smoothly transitions givens X to TX using a given divisor. Rounds the
  3. // amount moved.
  4. const move = (tx - x) / divisor
  5. if (move > 0.5) {
  6. return x + Math.ceil(move)
  7. } else if (move < -0.5) {
  8. return x + Math.floor(move)
  9. } else if (tx > 0) {
  10. return Math.ceil(tx)
  11. } else {
  12. return Math.floor(tx)
  13. }
  14. }