ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chad Specter
Expression to switch to the next frame in a sequence at a random time
on Mar 2, 2017 at 8:13:10 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 &lt;= time; i += dur){
seedRandom(i,true);
n ++;
}
framesToTime(n);


Return to posts index

Dan Ebberts
Re: Expression to switch to the next frame in a sequence at a random time
on Mar 2, 2017 at 9:26:55 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



Return to posts index

Chad Specter
Re: Expression to switch to the next frame in a sequence at a random time
on Mar 3, 2017 at 5:51:19 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);


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]