*@param{[Vector]}controlPointsAnarrayofcontrolpointstooperateon.Youshouldn't need to set this parameter - it'sonlyhereduetotherecursivenativeoftheinterpolationalgorithm.
*@return{Vector}Theinterpolatedpoint.
*/
interpolate(time,controlPoints)
{
// If the control points are undefined, then pick up our own control points
if(typeofcontrolPoints=="undefined")
controlPoints=this.controlPoints;
// Make sure that the time is between 0 and 1.
if(time<0||time>1)
thrownewError(`The time specified was out of bounds! It should be between 0 and 1, but a value of ${time} was provided.`);
// Create an array to store the interpolated points in
varinterpolatedPoints=[];
// Loop over all the control points, except the last one
for(leti=0;i<controlPoints.length-1;i++)
{
// Find the difference between the current point and the next one along
// To get the vector of the line between 2 points, you do b - a for the points a and b.
// Return the first item of the array if we still have an array. If it
// isn't an array, it must mean that one of our recursive calls has
// already broken the vector out of the array.
if(Array.isArray(interpolatedPoints))
returninterpolatedPoints[0];
else
returninterpolatedPoints;
}
/**
*Addthebeziercurvetothecurrentpathoncontext.Rememberthatthismethoddoesn't call context.beginPath(), nor does it fill or stroke anything. In addition, it does a lineTo the first point, so you'llneedtodoamoveTomanuallyifitisdesired.