(Page 4 of 4 pages for this article « First < 2 3 4)
Sunday, June 06, 2010
Deeper Modes of Expression, Part 6: Managing Time, Layer Numbers, Speed, and Velocity
Chris Meyer | 06/06
Ways of manipulating time with expressions, including having one layer echo the movements of another with delay.
Keyframe and Marker Time
In addition to accessing values at certain times, After Effects allows you to access values at certain keyframes or markers. You can also access the time at which markers and keyframes are placed. This means, for example, you can have an animation triggered by the placement of markers.
To find the time of the keyframe that is nearest to the current time, use nearestKey(time).time. To find the time of this layer’s nearest layer marker, use marker.nearestKey(time).time; to find the nearest comp marker, use thisComp.marker.nearestKey(time).time. To find the time at which a numbered comp marker is located, use thisComp.marker.key() and place the desired marker number in quotes. For example, thisComp.marker(“1”) returns the time of marker #1. If you leave out the quotes, After Effects will return the time of the first marker, not the marker numbered “1.” If the marker has not been created or assigned, you may get an error.
To find how close you are in time to the nearest keyframe or layer marker, just subtract time from either of those expression phrases. This will give you a positive value if the current time is just before the nearest keyframe or marker (in other words, the current time is a smaller number than the time of the nearest key), and a negative value if the current time is just after the nearest keyframe or marker.
If you need the absolute value of this difference in time (in other words, a positive number regardless of whether you are before or after the nearest keyframe or marker), use the Math.abs(value) expression discussed earlier in this chapter – for example, Math.abs(marker.nearestKey(time).time – time).
In our final example in this installment, we’ve trained an alarm clock to scale up to 50% as it crosses a layer marker, and to scale back down to 0% whenever it is more than 0.5 seconds away from the nearest marker:
  

In this example, an alarm clock’s scale varies depending on how close the time indicator is to a layer marker. The three images on top are taken at 00:00, 01:00, and 02:00; look at the Timeline panel above and observe the relationship between markers and time. Alarm clock courtesy Classic PIO/Sampler; background courtesy Digital Vision/Inner Gaze
To do this, we used the following expression applied to its Scale property:
time_to_marker = Math.abs(time - marker.nearestKey(time).time);
linear(time_to_marker, 0, 0.5, [50,50], [0,0])
The first line is the same as we just discussed: Get us the absolute value of the difference between the current time, and the time of the nearest marker. The second line uses a linear interpolation method (discussed in an earlier installment) to look at this time difference. As this difference varies between 0 (right on top of a marker) and 0.5 seconds (0.5 seconds away from the nearest marker), it produces a number that varies proportionally between [50,50] and [0,0]. We used the double values inside brackets because Scale is an array with two dimensions (three, if the layer was in 3D); just plugging in 50 or 0 would not work.
Hopefully, you can start to think of some creative applications of letting markers trigger animation events. For example, you can set up the expression, then add markers by tapping along with a piece of music or narration. There are other expressions you can create to extract the values of properties at specific keyframes or markers, or even to determine how many markers or keyframes a layer has. These features are discussed in the online Help file.
Next Installment: Making Decisions
Our next installment will discuss one of the most complex subjects in expressions: how to make decisions. This includes if/then/else statements for animation decisions and error checking, do/while loops to create “simulation” animations, and additional notes on equivalence tests, accumulating values inside loops, and formatting expressions. 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 4 of 4 pages for this article « First < 2 3 4)
You must be registered to comment. This is an effort to reduce spam. Please REGISTER HERE.
|