12 August 2008

flash: bezier curve point

A bit of actionscript to interpolate a point at location 0<=i<=1 along a bezier curve defined by an array of control points, cPoints, of Points (from the flash.geom package):

function getBezierPoint(cPoints:Array, i:Number):Point {
if (cPoints.length > 2) {
var subCPoints:Array = new Array();
for (var j:Number = 0; j < cPoints.length - 1; j++) {
subCPoints.push(Point.interpolate(cPoints[j], cPoints[j+1], 1-i));
}
return getBezierPoint(subCPoints, i);
} else {
return Point.interpolate(cPoints[0], cPoints[1], 1-i);
}
}


Flash probably has this sort of function built in, but oh well, it's done =)

No comments: