(Page 2 of 2 pages for this article < 1 2)
Saturday, May 01, 2010
Deeper Modes of Expression, Part 5: Comp, Footage, and Layer Attributes
Chris Meyer | 05/01
Grabbing numbers from places such as the comp settings.
Frames and Seconds
Expressions, as well as most effects, think of time in terms of seconds. However, most animators think of time in term of number of frames. You can use comp and footage attributes to automatically translate between the two for you.
After Effects features a pair of expression methods – timeToFrames() and framesToTime() – which make it easy to convert these two ways of representing time. You can enter one, two, or three parameters in the () of these methods. If you enter just one number, it is used as the time or frame number you want to convert from. For example, if you want to know the current frame number of a composition, you would write timeToFrame(time) (as time is always the current time in a composition, in seconds).
If you enter two numbers inside the () for these methods (separated by commas), the first number is still the time or frame number, and the second number is the fps (frames per second) value. This number defaults to the comp’s current frame rate; if you instead wanted to know how the current time in seconds would translate to a frame number if the frame rate was 12 fps, you would write timeToFrames(time, 12).
The third, optional value inside () is known as isDuration; it defaults to false. If instead of an absolute frame or time number, you were calculating the difference between two different values, the result may be negative. (This is where the potential rounding errors we discussed back in the first installment with Math.floor and Math.ceil might creep in.) If you set this value to true, the result will always be rounded away from 0, which is generally what you want. Say you had an expression where you calculated a value – time_difference – that you now wanted to convert to the nearest whole frame, at a rate of 24 fps: You would use timeToFrames(time_difference, 24, true).
A simple example of using one of these methods is shown here. The Echo effect requires you to set its Echo Time as a number of seconds. To compute this as a number of frames, we added a Slider Control where we could set the number of frames. Then for the Echo Time parameter, we wrote framesToTime(, dragged the pick whip to our slider, typed ), and press Enter. The resulting expression is:
In addition to these handy time and frame methods, After Effects also provides a pair of attributes to help us find the duration of a frame, either at the comp’s frame rate, or the source layer’s frame rate:
- thisComp.frameDuration: the length (in seconds) of one frame, using the comp’s current frame rate
- source.frameDuration: the length (in seconds) of one frame of the source or precomp, using its own frame rate instead of the comp’s
To convert either of these to a frame rate value, rather than a frame duration, place 1 / before them. For example, 1 / thisComp.frameDuration gives you the comp’s frame rate.
(A complete list of attributes is available as part of the Expression Language Reference section of the After Effects Online Help.)
Next Installment: Managing Time
Continuing the theme of calculating time, the next installment will discuss tricks such as setting up delayed animations using valueAtTime, using indexing to change a layer’s values based on its index in the Timeline, finding the rate at which a value changes, and triggering animations based on markers. Until then…
We’re in the process of serializing the Deeper Modes of Expression bonus chapter from our book Creating Motion Graphics with After Effects into a set of 12 posts here on PVC.
The next edition of Creating Motion Graphics - for After Effects CS5 - is due out by the end of June 2010.
The content contained in Creating Motion Graphics with After Effects - as well as the CMG Blogs and CMG Keyframes posts on ProVideoCoalition - are copyright Crish Design, except where otherwise attributed.
(Page 2 of 2 pages for this article < 1 2)
You must be registered to comment. This is an effort to reduce spam. Please REGISTER HERE.
|