home *** CD-ROM | disk | FTP | other *** search
Wrap
/*************************************************************** ADOBE SYSTEMS INCORPORATED Copyright 2002 Adobe Systems Incorporated All Rights Reserved NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe. ***************************************************************/ /*************************************************************** Author: Mary Obelnicki ***************************************************************/ /*************************************************************** This is the base constructor class for a Cubic Bezier object. The constructor takes four arguments: startPt, startControl, endControl, and endPt. Each argument is assumed to be a 2-dimensional vector object. (See Vector.js) startPt - The start vector point startControl - The control point for the start vector point endControl - The control point for the end vector point endPt - The end vector point The constructor has three methods: CubicBezier.xValue(t) and CubicBezier.yValue(t) These methods return the x and y values (respectively) of the bezier curve at time <t>. CubicBezier.pointAt(t) This method is based on the two above methods. Instead of returning a short of the coordinate, pointAt() returns a vector point object of the bezier curve at time <t>. The class has two methods that work with LiveMotion automation scripting. These two methods take in a LiveMotion path object and return a CubicBezier object. CubicBezier.pathSegmentToBezier(pathObject, firstKnot, secondKnot) returns a CubicBezier object representing the segment start at <firstKnot>. The returned bezier is in the same coordinate space as <pathObject>. The returned bezier reflects the base shape of <pathObject>. The bezier does not express any post-transforms applied to <pathObject>. CubicBezier.pathToBeziers(pathObject, pathIndex) based on the above function, pathToBeziers() returns an array of CubicBezier objects representing an entire path at <pathIndex> in <pathObject>. Note: a LMPathObject may contain multiple paths. ***************************************************************/ /*************************************************************** DO NOT EDIT BELOW THIS LINE ***************************************************************/ #include "Vector.js" function CubicBezier(startPt, startControl, endControl, endPt) { this.startX = startPt.x; this.startY = startPt.y; this.startControlX = startControl.x; this.startControlY = startControl.y; this.endControlX = endControl.x; this.endControlY = endControl.y; this.endX = endPt.x; this.endY = endPt.y; } CubicBezier.prototype.xValue = function(t) { var inverseT = 1 - t; var returnX = inverseT*inverseT*inverseT*(this.startX); returnX += 3*t*inverseT*inverseT*(this.startControlX); returnX += 3*t*t*inverseT*(this.endControlX); returnX += t*t*t*(this.endX); return returnX; }; CubicBezier.prototype.yValue = function(t) { var inverseT = 1 - t; var returnY = inverseT*inverseT*inverseT*(this.startY); returnY += 3*t*inverseT*inverseT*(this.startControlY); returnY += 3*t*t*inverseT*(this.endControlY); returnY += t*t*t*(this.endY); return returnY; }; //returns a Vector representing the point at <t> CubicBezier.prototype.pointAt = function(t) { return new Vector(this.xValue(t), this.yValue(t)); }; // returns a CubicBezier representing the segment starting at knot, // <firstKnot> and ending with <secondKnot>. The returned bezier is // in the same coordinate space as <pathObject>. The returned bezier // reflects the base shape of the pathObject, it does not express any // transforms applied to the path object. CubicBezier.pathSegmentToBezier = function(pathObject, firstKnot, secondKnot) { var degToRads = Math.PI/180; // maintains positive y as down. var startPt = new Vector(pathObject.position.x + firstKnot.position.x, pathObject.position.y + firstKnot.position.y); var startControl = new Vector(pathObject.position.x + firstKnot.position.x + firstKnot.leaveHandle.radius*Math.cos(firstKnot.leaveHandle.angle*degToRads), pathObject.position.y + firstKnot.position.y - firstKnot.leaveHandle.radius*Math.sin(firstKnot.leaveHandle.angle*degToRads)); var endControl = new Vector(pathObject.position.x + secondKnot.position.x + secondKnot.enterHandle.radius*Math.cos(secondKnot.enterHandle.angle*degToRads), pathObject.position.y + secondKnot.position.y - secondKnot.enterHandle.radius*Math.sin(secondKnot.enterHandle.angle*degToRads)); var endPt = new Vector(pathObject.position.x + secondKnot.position.x, pathObject.position.y + secondKnot.position.y); return new CubicBezier(startPt, startControl, endControl, endPt); } // returns an array of CubicBeziers representing path at <pathIndex> // in <pathObject>. CubicBezier.pathToBeziers = function(pathObject, pathIndex) { var returnBeziers = new Array; var thePath = pathObject.paths[pathIndex]; var theKnots = thePath.knots; var i=0; while(i < theKnots.length - 1) { returnBeziers[i] = CubicBezier.pathSegmentToBezier(pathObject, theKnots[i], theKnots[i+1]); i++; } //if the path is closed if(thePath.closed){ returnBeziers[i] = CubicBezier.pathSegmentToBezier(pathObject, theKnots[i], theKnots[0]); } return returnBeziers; }