Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Combinations / permutations on after effects

  • Combinations / permutations on after effects

    Posted by Gon Perdigao on November 13, 2012 at 12:04 pm

    Hi there,

    I’m struggling with a work that i have 3 position for 9 people that can only be in one position at a time for 10 seconds and them have to change for another one.

    So by my math is about 9*9(the position that each person can occupied each position)*3 (the number of position available) 243 possible combinations.

    Is there a script based on the index of the layer or the number of the footage to arrange a comp with this 243 possibles combinations?

    Dan Ebberts replied 13 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    November 13, 2012 at 2:21 pm

    I think there would be 504 permutations (9*8*7) and code like this should generate all of them:


    for (var i = 1; i <= 9; i++){
    for (var j = 1; j <= 9; j++){
    if (j == i) continue;
    for (var k = 1; k <= 9; k++){
    if ((k == i ) || (k == j)) continue;
    // do stuff
    }
    }
    }

    The code to actually moves the footage into the comp is going to depend on how you have things organized.

    I hope that gets you started.

    Dan

  • Gon Perdigao

    November 13, 2012 at 2:37 pm

    Thanks Dan you rock!!

    But why do you say that should be 504 permutations (9*8*7) i don’t understand where comes the 9*8*7 ?

    And by the way where do i apply the code? To each layer or to a comp with all the layers inside?

    Thanks a lot for all the help!

  • Dan Ebberts

    November 13, 2012 at 4:31 pm

    The 9*8*7 comes from 9 choices for the first slot, which leaves 8 choices for the second slot, which leaves 7 choices for the third slot.

    You probably wouldn’t use that code unless you put together a script to build the comp for you.

    If you set up the comp by hand, with copies of all nine footage items in each of the three slots (assume slot 1 is layers 1-9, slot 2 is layers 10-18, and slot 3 is layers 19-27), you could use an opacity expression like this to calculate which layers should be visible, based on the current time:

    dur = 10;
    maxPerm = 9*8*7;
    curPerm = Math.floor(time/dur)%maxPerm;
    i = Math.floor(curPerm/56)+1;
    j = Math.floor(curPerm%56/7)+1;
    k = curPerm%7+1;
    if (j >= i) j++;
    if (k >= i) k++;
    if (k >= j) k++;
    if ((index == i) || (index == j+9) || (index == k+18)) 100 else 0

    This should give you a different permutation every 10 seconds.

    Dan

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