Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions After Effects random position as a loop

  • After Effects random position as a loop

    Posted by Ian Durward on May 21, 2014 at 1:06 pm

    I am trying to animate a line that moves randomly in the Y direction. This is easy enough but the problem is that I need the start and end frame to be the same so that the result is a constant loop. The code I have so far is

    segDur = .5;
    minVal = [64,0];
    maxVal = [64, thisComp.height];

    seed = Math.floor(time/segDur);
    segStart = seed*segDur;
    seedRandom(seed,true);
    startVal = random(minVal,maxVal);
    seedRandom(seed+1,true);
    endVal = random(minVal,maxVal);
    ease(time,segStart,segStart + segDur, startVal, endVal);

    Any help is appreciated

    Darby Edelen replied 12 years, 3 months ago 2 Members · 5 Replies
  • 5 Replies
  • Darby Edelen

    May 22, 2014 at 3:53 am

    The description you’ve provided of your desired behavior is a little ambiguous.

    Can you give a more detailed description of how the line should move randomly? From the look of your current expression it seems that the line is choosing random start and end points but moving continuously between them. If, however, the start and end points of each loop are required to be the same then the start and end points will no longer appear random.

    Based on your current description and the approach you were taking with your expression this is what I came up with:

    segDur = .5;
    minVal = [64,0];
    maxVal = [64, thisComp.height];
    loop = time % segDur;
    seed = Math.floor(loop);
    segStart = 0;
    seedRandom(seed,true);
    startVal = random(minVal,maxVal);
    seedRandom(seed+1,true);
    endVal = random(minVal,maxVal);
    if(loop < segStart + segDur / 2) ease(loop,segStart,segStart + segDur / 2, startVal, endVal);
    else ease(loop, segStart + segDur / 2, segStart + segDur, endVal, startVal);

    But as you can see this doesn’t appear random. A clearer description of the desired behavior is probably required.

    Darby Edelen

  • Ian Durward

    May 22, 2014 at 11:12 am

    I need a set start and end point (the same location) but then need the line to move randomly in between.

    So say the clip will be 10 seconds. I need it to start at a set location. Then move randomly every .5sec and then at the end of the clip (10sec mark) it will end up back at the start position.

    This way when it is played back as a loop in VJ software it will be one continues loop with no jumping at the start and end of the loop.

    I hope that helps to explain what I am trying to achieve.

  • Darby Edelen

    May 22, 2014 at 3:59 pm

    Okay, the loop is 10 seconds long, but is the random motion every 0.5 seconds supposed to be random start/end points with continuous motion in between? Or should the line jump to a new location every 0.5 seconds and hold position until the next jump?

    Darby Edelen

  • Ian Durward

    May 23, 2014 at 1:14 am

    It needs to be exactly as my original code. Only difference is that the initial start point point and final end point need to be the same.

  • Darby Edelen

    May 23, 2014 at 11:56 pm

    This adjusts the last endVal to be the same as the first startVal. Changes to your original code are bold red.

    segDur = .5;
    loop = thisComp.duration;
    x = 1;
    n = loop / segDur;
    if(time > loop – segDur) x = 1 – n;

    minVal = [64,0];
    maxVal = [64, thisComp.height];

    seed = Math.floor(time/segDur);
    segStart = seed*segDur;
    seedRandom(seed,true);
    startVal = random(minVal,maxVal);
    seedRandom(seed+x,true);
    endVal = random(minVal,maxVal);
    ease(time,segStart,segStart + segDur, startVal, endVal);

    Darby Edelen

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