ADOBE AFTER EFFECTS: Forum Expressions Tutorials Podcasts Creative Cloud

Display Random Layer

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Eric BarkerDisplay Random Layer
by on May 19, 2011 at 7:07:15 pm

Alright, I know and have used the traditional method of creating a random image slideshow: precompose all the images, make them all one frame long, and then write a time remapping expression to jump between images.

Furthermore, that will work for my current application (and it's probably what I'll do)

However, I'm curious if there's a more direct method that would be even more expandable. I was thinking of using something like "Compound Arithmatic" on a solid layer, and then writing an expression to randomly choose layers. Unfortunately, I'm noticing that none of the layer controllers (even the "Layer Control" effect itself) are keyframeable/programmable. But there MUST be a way of doing this: manually compositing, and then being able to program what layer gets composited.

The time remapping method, as much as I've used it, has always seemed like a hack or workaround, and when I'm programming, I don't like to feel like I'm hacking to make something work, unless I absolutely have to.

Television Producer
KTVF-11 Fairbanks, Alaska

Return to posts index

Walter SoykaRe: Display Random Layer
by on May 19, 2011 at 7:31:35 pm

See my post in this thread [link] for an idea that might get you started.

The idea there was to create a controller layer with a randomized Slider effect, which we used to determine which layer to show. Each of the layers in that comp had an expression on their Opacity properties that looked to that slider to figure out what its own individual opacity should be at any given moment.

Obviously your case is a bit more involved than the "fast random cuts" example in the thread above, but a similar controller set-up that takes time into account might be a useful way of thinking about it -- you could use it to drive animation beyond simple cuts.

Even if you don't use that, instead using the static Layer control, you can use numbers to dynamically address layers by their index.

Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog - What I'm thinking when my workstation's thinking
Creative Cow Forum Host: Live & Stage Events

Return to posts index

Eric BarkerRe: Display Random Layer
by 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);

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

Return to posts index

Eric BarkerRe: Display Random Layer
by on May 19, 2011 at 9:15:56 pm

Eh, that caused some problems when trying to animate the Framehold value, because every time the value would switch, the math might work to make the picture switch at the very next frame again. Basically every time the framehold value change, it would suddenly pick a new image, and it looked very glichy.

So in the end, I did it the way AE wants you to do it:



I guess that's nice, you can force AE to only evaluate your expression every x amount of frames. I was just hoping to challenge myself to do this on my own, but I'm running out of time.

Television Producer
KTVF-11 Fairbanks, Alaska

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2016 All Rights Reserved