Adobe 0046100128056 Scripting Guide - Page 68
Transforming points, You also can use
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 68 highlights
CHAPTER 5: Working with Page Items Transforming Page Items 68 Transforming points You can transform points as well as objects, which means scripts can perform a variety of mathematical operations without having to include the calculations in the script itself. The ChangeCoordinates sample script shows how to draw a series of regular polygons using this approach: //General purpose routine for drawing regular polygons from their center point. function myDrawPolygon(myParent, myCenterPoint, myNumberOfPoints, myRadius, myStarPolygon, myStarInset){ var myTransformedPoint; var myPathPoints = new Array; var myPoint = [0,0]; if(myStarPolygon == true){ myNumberOfPoints = myNumberOfPoints * 2; } var myInnerRadius = myRadius * myStarInset; var myAngle = 360/myNumberOfPoints; var myRotateMatrix = app.transformationMatrices.add({ counterclockwiseRotationAngle:myAngle}); var myOuterTranslateMatrix = app.transformationMatrices.add({ horizontalTranslation:myRadius}); var myInnerTranslateMatrix = app.transformationMatrices.add({ horizontalTranslation:myInnerRadius}); for (var myPointCounter = 0; myPointCounter < myNumberOfPoints; myPointCounter ++){ //Translate the point to the inner/outer radius. if ((myStarInset == 1)||(myIsEven(myPointCounter)==true)){ myTransformedPoint = myOuterTranslateMatrix.changeCoordinates(myPoint); } else{ myTransformedPoint = myInnerTranslateMatrix.changeCoordinates(myPoint); } myTransformedPoint = myRotateMatrix.changeCoordinates(myTransformedPoint); myPathPoints.push(myTransformedPoint); myRotateMatrix = myRotateMatrix.rotateMatrix(myAngle); } //Create a new polygon. var myPolygon = myParent.polygons.add(); //Set the entire path of the polygon to the array we've created. myPolygon.paths.item(0).entirePath = myPathPoints; //If the center point is somewhere other than [0,0], //translate the polygon to the center point. if((myCenterPoint[0] != 0)||((myCenterPoint[1] != 0))){ var myTranslateMatrix = app.transformationMatrices.add({ horizontalTranslation:myCenterPoint[0], verticalTranslation:myCenterPoint[1]}); myPolygon.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.centerAnchor, myTranslateMatrix); } } //This function returns true if myNumber is even, false if it is not. function myIsEven(myNumber){ var myResult = (myNumber%2)?false:true; return myResult; } You also can use the changeCoordinates method to change the positions of curve control points, as shown in the FunWithTransformations sample script.