-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
InOut.js
56 lines (51 loc) · 1.35 KB
/
InOut.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* 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.
*/
var InOut = function (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
{
var 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;
}
}
};
module.exports = InOut;