UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

37 lines (31 loc) 1.05 kB
/** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var Bernstein = require('../Bernstein'); /** * Performs a generalized Bezier interpolation over an arbitrary number of control points. * The `v` array provides the control point values and `k` (0 to 1) determines the position * along the curve. Unlike CubicBezierInterpolation which uses exactly 4 points, this * supports any number. * * @function Phaser.Math.Interpolation.Bezier * @since 3.0.0 * * @param {number[]} v - The input array of values to interpolate between. * @param {number} k - The percentage of interpolation, between 0 and 1. * * @return {number} The interpolated value. */ var BezierInterpolation = function (v, k) { var b = 0; var n = v.length - 1; for (var i = 0; i <= n; i++) { b += Math.pow(1 - k, n - i) * Math.pow(k, i) * v[i] * Bernstein(n, i); } return b; }; module.exports = BezierInterpolation;