ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Random frame time remap

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Harry Hoag
Random frame time remap
on Mar 9, 2009 at 5:21:41 pm

Hi,

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
Russ



Return to posts index

Filip Vandueren
Re: Random frame time remap
on Mar 9, 2009 at 6:37:57 pm

Hy 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;




Return to posts index

Harry Hoag
Re: Random frame time remap
on Mar 9, 2009 at 7:12:38 pm

hey 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



Return to posts index


Filip Vandueren
Re: andom frame time remap
on Mar 9, 2009 at 8:36:31 pm

Oops,

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);



Return to posts index

Filip Vandueren
Re: andom frame time remap
on Mar 9, 2009 at 8:39:38 pm

Also, 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.



Return to posts index

Harry Hoag
Re: andom frame time remap
on Mar 9, 2009 at 9:43:48 pm

cool 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, 5

really thanks a lot for doing this!



Return to posts index


Filip Vandueren
Re: andom frame time remap
on Mar 9, 2009 at 11:06:08 pm

Okay, 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.




Return to posts index

Harry Hoag
Re: andom frame time remap
on Mar 9, 2009 at 11:13:44 pm

fantastic!
you were right, i had comp at 12 fps and footage at 25...
thanks man works a treat!!



Return to posts index

Ryan Irilli
Re: andom frame time remap
on Mar 25, 2009 at 8:47:03 pm

This 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!!!


Return to posts index


Gergely Szilard
Re: andom frame time remap
on Feb 25, 2011 at 11:25:16 am

Hi
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


Return to posts index

Erik Waluska
Re: andom frame time remap
on Mar 31, 2016 at 10:26:38 pm

Thanks, 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


Return to posts index

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