/
CubicBezierInterpolation.js
64 lines (56 loc) · 1.14 KB
/
CubicBezierInterpolation.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
57
58
59
60
61
62
63
64
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* @ignore
*/
function P0 (t, p)
{
var k = 1 - t;
return k * k * k * p;
}
/**
* @ignore
*/
function P1 (t, p)
{
var k = 1 - t;
return 3 * k * k * t * p;
}
/**
* @ignore
*/
function P2 (t, p)
{
return 3 * (1 - t) * t * t * p;
}
/**
* @ignore
*/
function P3 (t, p)
{
return t * t * t * p;
}
/**
* A cubic bezier interpolation method.
*
* https://medium.com/@adrian_cooney/bezier-interpolation-13b68563313a
*
* @function Phaser.Math.Interpolation.CubicBezier
* @since 3.0.0
*
* @param {number} t - The percentage of interpolation, between 0 and 1.
* @param {number} p0 - The start point.
* @param {number} p1 - The first control point.
* @param {number} p2 - The second control point.
* @param {number} p3 - The end point.
*
* @return {number} The interpolated value.
*/
var CubicBezierInterpolation = function (t, p0, p1, p2, p3)
{
return P0(t, p0) + P1(t, p1) + P2(t, p2) + P3(t, p3);
};
module.exports = CubicBezierInterpolation;