Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Flip a layer randomly

  • Flip a layer randomly

    Posted by Jonas Hed on December 2, 2014 at 9:32 pm

    Hello everyone this is my first post here and I am all new to expressions.

    This is what I want to do:
    Flip my layer randomly on every new frame to these values only (normal-without flipping, horizontally, vertically, horizontally+vertically).

    I have searched for hours to find this (it seems it does not have to be so complicated?) but no luck.
    Hope to get some help from the pros.

    Thanks in advance!

    Jonas Hed replied 11 years, 5 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    December 2, 2014 at 10:26 pm

    Try this scale expression:

    n = Math.floor(random(4));
    if (n ==0)
    value
    else if (n == 1)
    [-value[0],value[1]]
    else if (n == 2)
    [value[0],-value[1]]
    else
    -value

    Dan

  • Jonas Hed

    December 2, 2014 at 10:42 pm

    Hello Dan it works perfectly!

    I do not understand how the math behind it works though.
    What is making the values scale -100% or 100%? Because I was hoping to use this for other things too, for example
    making the layer rotate only 0, 90 or 180 degrees.

    Really appreciate your good and quick response thank you so much!

  • Dan Ebberts

    December 2, 2014 at 11:23 pm

    value returns the current value of the property (as an array for 2D or 3D properties). So for a layer with scale at 100% value would be [100,100]. Flipping just x would be [-value[0],value[1]] ([-100,100]) Flipping x and y would be -value ([-100,-100]). etc.

    Dan

  • Dan Ebberts

    December 2, 2014 at 11:28 pm

    Your 0, 90, 180 rotation example would look like this:

    n = Math.floor(random(3));
    if (n ==0)
    value
    else if (n == 1)
    value + 90
    else
    value + 180

    Dan

  • Jonas Hed

    December 2, 2014 at 11:54 pm

    Wow that cleared it all up!

    Thanks again!

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