Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Odd/Even Markers

  • Posted by Mike Clasby on June 7, 2007 at 6:42 pm

    Is there a way to distinguish odd and even numbered markers?

    I trying to do a cascading text like in Stranger Than Fiction. I keyframes a #D text layer’s x orientation to flop the text, then moving the anchor point, flopping again, and the text cascades down the screen. There is a pause of time so the text pause after each flop, so that I can apply the following dampening expression to X Rotation.

    amp=70; //amplitude (pixels)
    freq=2; //frequency (cycles per second)
    decay=2.5; //decay time (seconds)

    // find previous marker

    n = 0; // assume haven’t reached a marker yet
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time){
    n–;
    }
    }

    if (n > 0) t = time – marker.key(n).time else t =0;
    a = amp*Math.sin(freq*t*Math.PI*2)/Math.exp(decay*t);
    a

    If I could have the last line be “a” on odd numbered markers, and be “- a” on even numbered markers, the dampening would look right. With only “a” as the last line, the text always kicks out in the same direction, and I want it to kick out first toward the viewer, then on the next marker kick out away from the viewer.

    Can expression differentiate odd or even numbered markers?

    Dan Ebberts replied 18 years, 11 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    June 7, 2007 at 6:48 pm

    Something like this should do it:

    if ((marker.key(n).index % 2) > 0) a else -a

    Dan

  • Mike Clasby

    June 7, 2007 at 7:24 pm

    Works a charm, except before the first keyframe where I get this error message:-(

    After Effects warning: Bad method arguments: This property has no keyframe number 0.
    Error occurred on line 17.
    Expression disabled.

  • Dan Ebberts

    June 7, 2007 at 8:00 pm

    OK – try this:

    amp=70; //amplitude (pixels)
    freq=2; //frequency (cycles per second)
    decay=2.5; //decay time (seconds)

    // find previous marker

    n = 0; // assume haven’t reached a marker yet
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time){
    n–;
    }
    }

    if (n > 0) t = time – marker.key(n).time else t =0;
    a = amp*Math.sin(freq*t*Math.PI*2)/Math.exp(decay*t);
    if ((n > 0) && ((marker.key(n).index % 2) == 0)) a = -a;
    a

    Dan

  • Mike Clasby

    June 8, 2007 at 1:58 am

    Thank you berry, berry much (the blackberries are blooming here).

    Works a charm.

  • Victor Nash

    June 9, 2007 at 1:06 am

    This quite interesting.. I was curious what’s causing the positive and then negative motion.. I know it’s in this

    if ((n > 0) && ((marker.key(n).index % 2) == 0)) a = -a;
    a

    I’d love an explanation on this last line. Im trying to dive in a deeper understanding of altering and creating my own expressions. Thanks, you guys are the best.

    = = victor = =

  • Dan Ebberts

    June 9, 2007 at 1:05 pm

    The next-to-last line basically says if there are any markers AND the previous marker index is an even number, flip the sign of variable a.

    The test for odd/even is made by using the JavaScript modulus operator “%”. This operator gives you the remainder of a division operation. So, use you can use %2 to find out if an integer is odd or even.

    0%2 = 0
    1%2 = 1
    2%2 = 0
    3%2 = 1
    4%2 = 0

    etc.

    Dan

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