Namespaces in Expressions
Hi: I'm learning how to use expressions, and as a start, I wrote an expression to "bounce" the scale of a shape (a circle) from the starting default (100%) down to 0 over a range defined by a marker. To do this, I wrote the following code (in an external file aeprocs.jsx):
"cdexp":function(timeNow,vNow,layer,tag,final)
// Exponentially-damped decay from initial default down to "final" value over
// a time range defined by the marker identified by "tag"
{
k1 = -3.0;
omega = 5.0;
markStart = layer.marker.key(tag).time;
markEnd = markStart + layer.marker.key(tag).duration;
if(timeNow < markStart)
{
nv = vNow[0];
}
else if(timeNow > markEnd)
{
nv = final;
}
else
{
delta = timeNow - markStart;
nv = vNow[0]*(Math.exp(k1*delta) * Math.cos(omega*delta));
}
return [nv,nv];
}I can now invoke this to make a "bounce down to 0" effect on the scale property of any 2D object in my composition by writing the following expression:
lib = footage("aeprocs.jsx").sourceData;
lib.cdexp(time,value,thisLayer,"1",0);Now a couple of questions:
- It is cumbersome to include the first statement (above, "lib = . . .") in every expression where I use this. Is there a way to insert "lib" into the global namespace so it can be defined once and used everywhere in the composition?
- The code as written here assumes a 2-dimensional property (scale in this case). Is there a way to "template" this code so I can write one bit of code which can then be used for 1D properties (e.g. opacity) or 2D properties (e.g. scale or position), or - for that matter - properties with other dimensions (e.g. color)?
Thanks.