ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Random frames without repeat

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kasper Werther
Random frames without repeat
on Oct 9, 2015 at 12:20:17 am

I've been searching around for a few hours to get this done.
I have a 12fps composition containing 132 unique frames. I want the composition to play the frames in random order, without repeating a frame.

I found multiple scripts, of which the one from this thread came very close: https://forums.adobe.com/message/4577715

fr = 12; // frame rate;

numFrames = 132;

seedRandom(index,true);

seg = Math.floor(time*fr);

f = Math.floor(random(numFrames));

for (i = 0; i < seg; i++)

f = (f + Math.floor(random(1,numFrames)))%numFrames;

framesToTime(f);


Only the thing is, I see frames being repeated a few times. I tried messing around a bit, but I can't seem to get it right. What do I add to prevent this? (and where in the code)


Return to posts index

Dan Ebberts
Re: Random frames without repeat
on Oct 9, 2015 at 5:14:24 am

Do you mean that you want each fame to display once, and only once in the complete sequence of frames, or do you just need the same frame to not show twice in a row?

Dan



Return to posts index

Kasper Werther
Re: Random frames without repeat
on Oct 9, 2015 at 10:02:28 am

I only want to display each frames once, and only once in the complete sequence of frames :)


Return to posts index


Dan Ebberts
Re: Random frames without repeat
on Oct 9, 2015 at 5:29:40 pm

I think this is close to what you're looking for:


numFrames = 132;
a = [];
seedRandom(index,true);
for (i = 0; i < numFrames; i++)a.push(i);
for (i = 0; i < numFrames; i++){
idx = i + Math.floor(random(a.length - i));
temp = a[i];
a[i] = a[idx];
a[idx] = temp;
}
idx = timeToFrames(time)%numFrames;
framesToTime(a[idx])



Dan



Return to posts index

Kasper Werther
Re: Random frames without repeat
on Oct 9, 2015 at 7:43:47 pm

It seems to work, I did not notice a repeated frame yet!
Thank you, much appreciated!


Return to posts index

Ilya Sire
Re: Random frames without repeat
on Nov 23, 2016 at 1:29:20 pm

Hi Dan Ebberts,

How to make this code always start with 0 frame and then next random?

Sire


Return to posts index

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