ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Re: Display Random Layer

COW Forums : Adobe After Effects

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


Eric Barker
Re: Display Random Layer
on May 19, 2011 at 8:50:39 pm

Wow, that's pretty much EXACTLY what I came up with after I typed that post. But, I made some modifications and made it even simpler, and less weird (I'll explain later):

framehold = 7; // use external Slider Controller to control this

seedRandom(Math.floor(timeToFrames(time)/framehold), true);
Math.floor(random(2,thisComp.numLayers+1));


Basically, it re-seeds the random number generator every 7 frames... or should I say, it seeds the random number generator with the same number for 7 frames, and therefor, it gives you the same random value for 7 frames in a row.

In the process, I discovered some ABSOLUTELY WEIRD things about the way AE evaluates JavaScript. First, it DEMANDS a value for every time it evaluates (which is every frame). I originally tried to accomplish this by getting the frame, and then use a conditional "!frame%7" to give me a new random value every 7 frames. Unfortunately, because AE demands a value output at every evaluation, it would use something else for the value, like another line, or if there is no line outside the conditional, it would simply use the value in the box. So while every 7th frame would give me a random number, it wouldn't hold onto that value. And since there's no way of globally storing variables (without tedious text object manipulation), AE would have no way of keeping the same value for 7 frame.

Secondly, I HATE the way that AE grasps at whatever it can find to fill it's value box. Evey line that's evaluated, gets temporarilly stored in the value box. So if you write "x=100;", then unless there's another math-based line, the box will remain at "100" after the cycle completes. I'd always asumed it was a variable called "value", because so many people mistakenly use "value = x;" for a final value assignment. But in reality, all you have to do is put "x" to accomplish this.

My inner-programmer is screaming bloody murder right now, this is SO WRONG!

Sorry... anyway, at least this expression works, and it works well. It definitely feels a lot better than using time remapping.

Television Producer
KTVF-11 Fairbanks, Alaska
video.ericbarker.com


Posts IndexRead Thread 


Current Message Thread:





© 2019 CreativeCOW.net All Rights Reserved
[TOP]