forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubicBezierInterpolation.js
More file actions
57 lines (47 loc) · 1.18 KB
/
Copy pathCubicBezierInterpolation.js
File metadata and controls
57 lines (47 loc) · 1.18 KB
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
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
function P0 (t, p)
{
var k = 1 - t;
return k * k * k * p;
}
function P1 (t, p)
{
var k = 1 - t;
return 3 * k * k * t * p;
}
function P2 (t, p)
{
return 3 * (1 - t) * t * t * p;
}
function P3 (t, p)
{
return t * t * t * p;
}
// p0 = start point
// p1 = control point 1
// p2 = control point 2
// p3 = end point
// https://medium.com/@adrian_cooney/bezier-interpolation-13b68563313a
/**
* A cubic bezier interpolation method.
*
* @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;