phaser/todo/TS Source/tweens/easing/Elastic.ts
2013-09-13 16:16:48 +01:00

76 lines
2.1 KiB
TypeScript

/// <reference path="../../_definitions.ts" />
/**
* @author Richard Davey <rich@photonstorm.com>
* @author sole (http://soledadpenades.com), tween.js
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser
*/
module Phaser.Easing {
/**
* Elastic easing methods.
*
* @class Elastic
*/
export class Elastic {
/**
* The In ease method.
*
* @method In
* @param {Number} k The value to ease.
* @return {Number} The eased value.
*/
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));
}
/**
* The Out ease method.
*
* @method Out
* @param {Number} k The value to ease.
* @return {Number} The eased value.
*/
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);
}
/**
* The InOut ease method.
*
* @method InOut
* @param {Number} k The value to ease.
* @return {Number} The eased value.
*/
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;
}
}
}