Move direction handles in synch with anchor point?


hi all

 

i'm trying nudge anchor points on object randomly (to informal look). (i know effects already.)

 

maintaining corner points no problem - set direction handles same coordinates anchor.

 

but can't nudge smooth point in way want to, move anchor maintain direction handles in same relation anchor had before. say, should remain smooth points.

 

my script calculates difference between 'before' , 'after' positions of anchor, , applies difference direction handles… in practice smooth points converted corners, because direction handles don't maintain relation anchor.

 

would grateful if can point out flaw(s!) in logic.

 

var docref = activedocument;

var objects = activedocument.selection.length;

var cshift = prompt("point shift (pt)",5);

 

 

// loop through objects

for(var count=0;count<objects;count++)

{

currentobj = activedocument.selection[count];

nudge(currentobj);

}

 

// function nudges each object

function nudge(obj)

var objpoints = obj.selectedpathpoints;

var objpointcount = objpoints.length;

 

for (var = 0;i<objpointcount;i++){

var thispoint = objpoints[i];

 

var va = thispoint.anchor[0];

var vb = thispoint.anchor[1];

var la = thispoint.leftdirection[0];

var lb = thispoint.leftdirection[1];

var ra = thispoint.rightdirection[0];

var rb = thispoint.rightdirection[1];

 

if(va==la && va==ra && vb==lb && vb==rb)

{ // if corner point, randomize anchor position

va = va +((math.random()*cshift));

vb = vb +((math.random()*cshift));

thispoint.anchor = array(va,vb);

 

// set direction handles @ same position, maintaining corner point

thispoint.leftdirection = array(va,vb);

thispoint.rightdirection = array(va,vb);

}

 

else

{ // not corner point: keep handles in same relative position shifted anchor

var va2 = va +((math.random()*cshift));

var vb2 = vb +((math.random()*cshift));

thispoint.anchor = array(va2,vb2);

 

// bit calculates random shift applied anchor

var anchorshifta = va2 - va;

var anchorshiftb = vb2 - vb;

 

// these lines apply same shift direction handles

thispoint.leftdirection[0] = la + anchorshifta;

thispoint.leftdirection[1] = lb + anchorshiftb;

thispoint.rightdirection[0] = ra + anchorshifta;

thispoint.rightdirection[1] = rb + anchorshiftb;

}}}

the else part modified:

else { // not corner point: keep handles in same relative position shifted anchor     var ashift = math.random()*cshift;     var bshift = math.random()*cshift;     thispoint.anchor = [va  + ashift, vb + bshift];     thispoint.leftdirection = [la + ashift, lb + bshift];     thispoint.rightdirection = [ra + ashift, rb + bshift]; } 


More discussions in Illustrator Scripting


adobe

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support