arcade-physics
Version:
Use Arcade Physics without Phaser.
50 lines • 1.47 kB
JavaScript
;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Elastic ease-in/out.
*
* @function Phaser.Math.Easing.Elastic.InOut
* @since 3.0.0
*
* @param {number} v - The value to be tweened.
* @param {number} [amplitude=0.1] - The amplitude of the elastic ease.
* @param {number} [period=0.1] - Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles.
*
* @return {number} The tweened value.
*/
const InOut = (v, amplitude, period) => {
if (amplitude === undefined) {
amplitude = 0.1;
}
if (period === undefined) {
period = 0.1;
}
if (v === 0) {
return 0;
}
else if (v === 1) {
return 1;
}
else {
let s = period / 4;
if (amplitude < 1) {
amplitude = 1;
}
else {
s = (period * Math.asin(1 / amplitude)) / (2 * Math.PI);
}
if ((v *= 2) < 1) {
return -0.5 * (amplitude * Math.pow(2, 10 * (v -= 1)) * Math.sin(((v - s) * (2 * Math.PI)) / period));
}
else {
return amplitude * Math.pow(2, -10 * (v -= 1)) * Math.sin(((v - s) * (2 * Math.PI)) / period) * 0.5 + 1;
}
}
};
exports.default = InOut;
//# sourceMappingURL=InOut.js.map