Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to switch to the next frame in a sequence at a random time

  • Expression to switch to the next frame in a sequence at a random time

    Posted by Chad Specter on March 2, 2017 at 8:13 pm

    I need an expression that will advance to the next frame in a sequence at a random time. I would like to give the expression the start frame and a min/max number of frames to hold. So something like this:


    startFrame = 12;
    minFrames = 100;
    maxFrames = 150;

    So sometime between frame 100-150 it will advance to the next frame, 13. I’ve been trying the following script which was based on one of Dan Ebberts’ for picking a random frame, but I have not got it to work for just advancing to the next frame at a random time without a stroboscopic effect happening.

    nFrames = 5;
    dur = .5;
    seedRandom(index,true);
    n = Math.floor(random(nFrames));
    for (i = 0; i <= time; i += dur){
    seedRandom(i,true);
    n ++;
    }
    framesToTime(n);

    Chad Specter replied 9 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 2, 2017 at 9:26 pm

    Try this:


    startFrame = 12;
    minFrames = 100;
    maxFrames = 150;
    fCur = timeToFrames(time);
    f0 = f1 = 0;
    nextFrame = startFrame-1;
    while (f1 <= fCur){
    f0 = f1;
    seedRandom(113 + f0,true);
    f1 += Math.round(random(minFrames,maxFrames));
    nextFrame++;
    }
    framesToTime(nextFrame);

    Dan

  • Chad Specter

    March 3, 2017 at 5:51 pm

    Thanks! Worked like a charm. I made a couple changes so that it will loop through a certain number of frames, but otherwise that was it. Man. After Effects really needs some sort of Javascript console to more easily debug these expressions.

    startFrame = 12;
    totalFrames = 100;
    minFrames = 100;
    maxFrames = 150;
    fCur = timeToFrames(time);
    f0 = f1 = 0;
    nextFrame = startFrame-1;
    while (f1 &lt;= fCur){
    f0 = f1;
    seedRandom(113 + f0,true);
    f1 += Math.round(random(minFrames,maxFrames));
    nextFrame = nextFrame+10;
    if (nextFrame >= totalFrames) {nextFrame = nextFrame-totalFrames}
    }
    framesToTime(nextFrame);

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