Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Would love some input

  • Would love some input

    Posted by Michael James on August 26, 2017 at 4:53 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

    Xavier Gomez replied 8 years, 12 months ago 2 Members · 1 Reply
  • 1 Reply
  • Xavier Gomez

    August 27, 2017 at 11:46 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];

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy