Tween function

by jonahe

HTML

<h2 id="status"></h2>

JavaScript

/* copied from https://gist.github.com/gre/1650294 */
/* Given a t (time progress) between 0 and 1 these will return a number (also beween 0 and 1) to multiply your number with.  For the value t = 0, these all give back 0. And for t = 1 they all return 1.   */
const EasingFunctions = {
  // no easing, no acceleration
  linear: function (t) { return t },
  // accelerating from zero velocity
  easeInQuad: function (t) { return t*t },
  // decelerating to zero velocity
  easeOutQuad: function (t) { return t*(2-t) },
  // acceleration until halfway, then deceleration
  easeInOutQuad: function (t) { return t<.5 ? 2*t*t : -1+(4-2*t)*t },
  // accelerating from zero velocity 
  easeInCubic: function (t) { return t*t*t },
  // decelerating to zero velocity 
  easeOutCubic: function (t) { return (--t)*t*t+1 },
  // acceleration until halfway, then deceleration 
  easeInOutCubic: function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 },
  // accelerating from zero velocity 
  easeInQuart: function (t) { return t*t*t*t },
  // decelerating to zero velocity 
  easeOutQuart: function (t) { return 1-(--t)*t*t*t },
  // acceleration until halfway, then deceleration
  easeInOutQuart: function (t) { return t<.5 ? 8*t*t*t*t : 1-8*(--t)*t*t*t },
  // accelerating from zero velocity
  easeInQuint: function (t) { return t*t*t*t*t },
  // decelerating to zero velocity
  easeOutQuint: function (t) { return 1+(--t)*t*t*t*t },
  // acceleration until halfway, then deceleration 
  easeInOutQuint: function (t) { return t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t }
}

/* 
	Goal: understand how tweening between two values it achieved, e.g. for "ticking" animations for increasing score etc.
  
  Tweening could be described as taking 4 parameters
  	a start value
    an end value
    a duration
    a change function which, depending on the current elapsed time, should give you the next value
    
  
  So we need to keep track of time / progress
    
*/

function createNormalizeFn(min,...