phaser/Phaser/system/easing/Elastic.ts
2013-04-18 14:16:18 +01:00

53 lines
1.5 KiB
TypeScript

/// <reference path="../../Game.ts" />
/**
* Phaser - Easing
*
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
*
* @version 1.0 - 11th January 2013
*
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
*/
module Phaser.Easing {
export class Elastic {
public static In(k) {
var s, a = 0.1, p = 0.4;
if (k === 0) return 0;
if (k === 1) return 1;
if (!a || a < 1) { a = 1; s = p / 4; }
else s = p * Math.asin(1 / a) / (2 * Math.PI);
return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
}
public static Out(k) {
var s, a = 0.1, p = 0.4;
if (k === 0) return 0;
if (k === 1) return 1;
if (!a || a < 1) { a = 1; s = p / 4; }
else s = p * Math.asin(1 / a) / (2 * Math.PI);
return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
}
public static InOut(k) {
var s, a = 0.1, p = 0.4;
if (k === 0) return 0;
if (k === 1) return 1;
if (!a || a < 1) { a = 1; s = p / 4; }
else s = p * Math.asin(1 / a) / (2 * Math.PI);
if ((k *= 2) < 1) return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
}
}
}