Transforming Points - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
5: Working with Page Items
HAPTER

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)){
}
else{
}
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
shown in the FunWithTransformations sample script.
myTransformedPoint = myOuterTranslateMatrix.changeCoordinates(myPoint);
myTransformedPoint = myInnerTranslateMatrix.changeCoordinates(myPoint);
changeCoordinates
method to change the positions of curve control points, as
Transforming Page Items 68

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents