const bezierCurve = { create(){ }, one(t,p1,p2){ const [x1,y1] = p1; const [x2,y2] = p2; let x = x1 + (x2 - x1) * t; let y = y1 + (y2 - y1) * t; return [x,y]; }, two(t,p1,cp,p2){ const [x1,y1] = p1; const [cx,cy] = cp; const [x2,y2] = p2; let x = (1 - t ) * ( 1 - t ) * x1 + 2 * t * ( 1 - t) * cx + t * t * x2; let y = (1 - t ) * ( 1 - t ) * y1 + 2 * t * ( 1 - t) * cy + t * t * y2; return [x,y]; }, three(){ const [x1,y1] = p1; const [cx1,cy1] = cp1; const [cx2,cy2] = cp2; const [x2,y2] = p2; let x = x1 * (1 - t ) * ( 1 - t ) * ( 1 - t ) + 3 * cx1 * t * ( 1 - t ) * ( 1 - t ) + 3 * cx2 * t * t * ( 1 - t ) + x2 * t * t * t; let y = y1 * (1 - t ) * ( 1 - t ) * ( 1 - t ) + 3 * cy1 * t * ( 1 - t ) * ( 1 - t ) + 3 * cy2 * t * t * ( 1 - t ) + y2 * t * t * t; return [x,y]; }, multi:(()=>{ var binomial = function(start,end){ var cs = 1,bcs = 1; while(end > 0){ cs *= start; bcs *= end; start --; end --; } return (cs/bcs); }; var getPoint = (points,t)=>{ var len = points.length; var x = 0,y = 0; for(var i = 0;i < len;i++){ var point = points[i]; x+= point[0]*Math.pow((1-t),(len - 1 - i)) * Math.pow(t,i) * (binomial(len - 1,i)); y+= point[1]*Math.pow((1-t),(len - 1 - i)) * Math.pow(t,i) * (binomial(len - 1,i)); } return [x,y]; } return function(points,amount){ var result = []; for(var i = 0 ; i < amount;i++ ){ var point = getPoint(points,i / amount); result.push(point); } return result; } })() }