Activity › Forums › Adobe After Effects Expressions › Random frame time remap
-
Random frame time remap
Posted by Harry Hoag on March 9, 2009 at 5:21 pmHi,
I have a boiling animation as a 5 frame image sequence, and to make the loop more interesting i want to randomise the frames.
I am totally new to expressions, i’ve looked about for a solution for the last half hour without luck.The frames need to be random and loop continuously without the same frame being repeated twice in a row or appear again after only one frame. So a frame needs a gap of at least two different frames before appearing again. (this is why I can’t simply use the wiggler)
help me please!!! this is too hard for me!!! 🙂
thanks
RussJim Lefevre replied 3 years, 9 months ago 6 Members · 11 Replies -
11 Replies
-
Filip Vandueren
March 9, 2009 at 6:37 pmHy Russ, try this:
seedRandom(index,true);
var t=timeToFrames();var r1=-1;
for (var i=0; i<=t; i++) { var r2=Math.floor(random(5)); // gives values from 0-4 if (r1==r2) t++; r1=r2; } r1; -
Harry Hoag
March 9, 2009 at 7:12 pmhey thanks for replying,
i’m guessing i simply add this to an expressions field on the time remap?
I tried that and it just flicks between the first and last frame of my 5 frame sequence…
did you test this code, or am i doing this wrong?thanks
-
Filip Vandueren
March 9, 2009 at 8:36 pmOops,
The expression is returning random integers between 0 and 4, and timeremapping treats those as seconds instead of framenumbers.
The last line should be:framesToTime(r1);
-
Filip Vandueren
March 9, 2009 at 8:39 pmAlso, Ive reread your first post and I forgot about the two frames gap. Now it’s a 1 frame gap between repeating values
I’ll rewrite when Im back at my computer in 2 hours. -
Harry Hoag
March 9, 2009 at 9:43 pmcool thanks,
it is working a bit better, but i’m getting repeated frames next to each other all the time and it’s not using all the frames. it’s only using 0, 2, 4, 5really thanks a lot for doing this!
-
Filip Vandueren
March 9, 2009 at 11:06 pmOkay, this is the final script:
seedRandom(1,true);
var t=timeToFrames();var r1=-3;
var r2=-2;
var r3=-1;
for (var i=0;t>=i; i++) {
var r3=Math.floor(random(5));
if (r1==r3 || r2==r3) {
t++;
continue;
}
r1=r2;
r2=r3;
}framesToTime(r3);
I get no repeated frames, no back and forth with only 1 frame in between, and all frames from 0 to 4
The only thing that could prevent some frames form being used is if the comp has a different framerate than the 5 frame footage.You can change the first line
seedRandom(1,true);to a different number and you’ll get another set of random values. -
Harry Hoag
March 9, 2009 at 11:13 pmfantastic!
you were right, i had comp at 12 fps and footage at 25…
thanks man works a treat!! -
Ryan Irilli
March 25, 2009 at 8:47 pmThis is exactly what I was looking for. Only thing is I am unsire what variable to change/add if my source is 8 frames long instead of 5…
Thank you!!!
-
Gergely Szilard
February 25, 2011 at 11:25 amHi
This really helped me out too
One more question: what would I need to do if a wanted to hold one image for 2 or 3 frames?
I tried a few things but I’m not too good at this…
Thank you -
Erik Waluska
March 31, 2016 at 10:26 pmThanks, Flip! This was a winner for me as well.
The way I made it hold for several frames is to precomp the clip and change it’s framerate to something low like 10 and then change the precomp’s settings to preserve framerate when nested.
Erik Waluska
EAWmedia
Reply to this Discussion! Login or Sign Up