ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Would love some input

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Michael James
Would love some input
on Aug 26, 2017 at 4:53:45 am

I'm very, very new to expressions and today I worked on a position expression for a project. For those who are seasoned in expressions, I'd love to hear any pointers you might have on where I could simplify. I know it's probably very redundant and quite honestly a mess, but it's tricky to pinpoint improvements as I'm just starting out.

Here's the expression: https://pastebin.com/Uhv6EZZ1

Basically I have an off-centered pre-rendered element that needs to align with other objects in the comp, but ALSO needs to be rotatable and mirrorable. The expression in question auto aligns by compensating the position, while giving you the ability to rotate in 90 degree increments and flip on X, Y, or both. After working on this expression I realize I'm repeating a lot of variables over and over again. But I'm not too sure on how I'd go about simplifying. Any thoughts?

Thanks!
-MJ


Return to posts index

Xavier Gomez
Re: Would love some input
on Aug 27, 2017 at 11:46:24 am

Here is an attempt to make it more compact. Not sure it actually brings something though.
Your expression is more readable.

Xavier

Px=transform.scale[0].value > 0; // Px true <==> positive xScale
Py=transform.scale[1].value > 0; // Py true <==> positive yScale
Rot=transform.rotation.value % 360; if (Rot<0) rot += 360;
cPos=transform.position.value;
i=0;
j=0;
if (Rot%90 === 0){
A = Rot%180 === 0; // true for 0 and 180, false for 90 or 270
// result for 0 and 90 :
if ( (Px===Py) ? (Px ? !A : A) : (!Px) ) i=1;
if ( A ? !Py : !Px) j=1;
// 180 or 270 : invert
if (Rot===180 || Rot===270){ i=1-i; j=1-j;};
};
// result
cPos + [14*i, 14*j];


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]