LIBRARY: Tutorials Reviews Interviews Editorials Features Business Authors RSS Feed

Using After Effects Expressions to Animate World Maps

COW Library : Adobe After Effects Tutorials : Mylenium : Using After Effects Expressions to Animate World Maps
Using After Effects Expressions to Animate World Maps
A CreativeCOW.net Adobe After Effects Tutorial


Using After Effects Expressions to Animate World Maps

Mylenium
Mylenium
http://www.mylenium.de
Germany

©Creativecow.net. All rights are reserved.

Article Focus:
These days even the smallest garage shops claim to be doing business all over the world so it's a quite common task to animate world maps and additional data related to their business. In this tutorial we will focus on a technique to represent a distribution or transport network. However, it can also be used to animate city maps or simply create other automated animation that applies the same paradigms.

Download the project files here.


So what?



At first our project doesn't look like much and if you're only sticking with those few lines you could even hand animate everything, but what if your network got quite massive and the timing more complex? Read on to explore a simple and elegant solution to this problem.


Step 1: Preparing the maps

In order to have something to animate over, we need to prepare our maps. Depending on the detail level required, this task can consume more time than the actual animation itself. Since there is an infinite number of possible combinations and techniques and a real guide would make little sense, I'm only providing a few tips and tricks that I find useful.

Focus on quality! Nothing gets served if you download some shabby free JPEGs from the web. Try to get vector based maps whenever possible.

When using vector based maps, see to it that all elements are drawn as cleanly as possible and can be separated into different groups and layers. Join broken lines, close open objects (where appropriate) and convert any outlines and strokes to real contours. The latter is especially important since outline info can easily get lost when using other than solid lines.

Vegetation and elevation maps mostly come as bitmaps. Make sure you get them in as high a resolution as possible but also don't overdo. Take care to adjust their colors and remove any artefacts and scratches. Try to separate them into logical parts using channels and masks in Photoshop and put them on layers so you can manipulate them separately. Name those layers properly.

Both with vector and bitmap maps I find it useful to work with grayscale only. All coloring/ tinting can easily be achieved using Tint, Fill and Colorama inside After Effects. It's much more intuitive and since it also is in destructive, you can always tweak things to perfection even very late in the production process.

Remove all unnecessary information! There is little point in having every street, house, railway etc. if they are not related to the subject itself. Simplification is the key to success. Don't forget that your resolution is limited and quite possibly your map will only be seen for a short time period.

Similarly, only use a limited color set. Pick out important parts in strong colors, but keep the rest subdued. Your grandma might be proud if you pick out her house on a world map in shining red, but your client might not like this at all. There is also no need to stick to the coloring conventions of real maps unless you want that look. It's more important to smoothly integrate your map into your existing design. Nothing looks more pesky than a map that looks like it's just been scanned from a real map without any effort going into remaking and adjusting it.

Keep labeling to a limited amount. If your clip is supposed to have voice-over anyway, displaying location names is often not necessary at all. If you need labeling, use a clear font and a strong color. Align your labels with the screen and not the map to improve legibility even on diagonal roads.

Beware of copyright issues. Maps are intellectual property and may be protected. Nobody can stop you from re-tracing a map or building your own stylized maps (it is considered an creative effort which does not touch copyrights of the original maps because you could just as easily take your own measurements or draw after aerial photographs), but using map material without any changes normally requires at least a permission of the copyright holder. The only exception to this are maps published by state authorities for public domain use.



Step 2: Animation controls and project structure

In order to keep things as uncluttered as possible, be able to tweak each element "to death" and make our expressions work, a certain project structure is required. This also helps After Effects' rendering pipeline to work more efficiently. We are going to need at least 3 compositions, but in many cases you will want to use 4 or more. I'll explain as to why later on.

First we need our main composition that is used for the final output. It should match whatever resolution/ size you need for your resulting movie. I chose to name it World Map Zoom.

Then naturally we need a composition to put our maps in. This will often be a very big and memory hungry composition, so be patient and plan ahead when working here. Name it World Map pre for the time being. At this point you have to decide if you want to add more details to your map like animated map symbols, cars on roads, trains on railways or more detailed maps for certain regions you are going to zoom-in on. Animate and style those in another sub comp and place them across your map. Beware that those elements will be scaled with the map as you pan and zoom about, so avoid putting critical elements such as label text in here! It's wiser to place such elements in a separate comp and use expressions to compensate for any loss of legibility. This is also important in terms of layer order - you may want this info to appear on top of the animated lines.

Our most important composition is World Map Lines. Here all fancy the stuff takes place. Quite obviously it must match the size of the map, but is easier to handle since it contains less massive elements.

For the sake of completeness, I created yet two other compositions labeled Target Point and Source Point that act as the start and end of our line. All they contain is a single layer with a circle shape whose size we're going to animate to compensate for the zooming.

With all those compositions now in place, go back to World Map Zoom and create a Null layer or a solid in it and name it Controller. We really only need this to hold a few sliders to which we are going to tie our expressions later on, so it should not be a visible layer. With your Controller selected, go to your Effects menu and choose Expression Controls -> Slider. The effects control window will open. Select the slider, hit Enter and rename it to Minimum Spread Time. Repeat this process and create sliders for Maximum Spread Time, Target Point Size, Source Point Size, Line Thickness and Point Fade in Time.


Helping After Effects a bit is actually quite easy. One of the core concepts of it is that everything occurs in a certain order. Sub-compositions will be evaluated before transformations, transformations before masks, masks before effects etc. Of course there are a few exceptions, but let's not burden ourselves with this. Instead let's use this knowledge to optimize our workflow.

By placing certain parts of our project into separate comps, we can force After Effects to look at them first. It will render all masks, effects and transformations and calculate the resulting RGB and Alpha values for each pixel. Those values are stored in an internal pixel buffer. Imagine this as an virtual image file where everything is "baked". If it now happens that in your sub-composition there is no animation at all ( = not a single parameter changes over time), After Effects will only do this once and then simply be able to forget about this comp until the next time you decide to change something inside of it. This will greatly save resources since always the already available pixel buffer will be used instead of re-calculating everything for each frame. So if you carefully place all static elements in separate comps, you will gain speed and make your life a lot easier.

One last important note: All this is of course still dependant on your computers resources. Even with all this optimizations it might be wiser to sometimes replace static compositions with a pre-rendered still frame of that same comp (use Save Frame as...) or use low-resolution proxies.


Step 3: They've got style. They've got grace... and soon they'll be all over the place!

All the following steps and expressions are only related to either modifying the look of our elements or facilitate their placement in a graceful and easy manner. Now let's get serious. We'll start with the simple things first.

Open your Target Point and Source Point compositions. Each of them should contain a solid with the Circle effect applied to it. Alt-click on the radius parameter to turn on expressions. Use the pick-whip and select the Target Point Size and Source Point Size on your Controller in your World Map Zoom composition. That's all for the time being and you can close your compositions again. If you want to use other shapes you should connect the sliders to the Scale property. Keep in mind that this property has at least two dimensions, so instead of directly pick-whipping it use this:
my_size=comp("World Map Zoom").layer("Controller").effect("Target Point Size")(Slider);

[my_size,my_size]
Move on to the comp named World Map Lines. Drag Source Point, Target Point and World Map pre as layers into that composition. Make sure the latter is the bottommost layer and lock it, so you won't incidentally move it later on. In addition to this create a long thin solid 10000 pixels wide and 100 pixels high and simply name it Line. Once more we are going to use a simple pick-whip expression on its Position property.
thisComp.layer("Source Point").position
On the Scale property of this line solid add the following expression:
full_length=length(position-thisComp.layer(index+1).position)/100;
thickness=comp("World Map straight Zoom").layer("Controller").effect("Line Thickness")("Slider") [full_length,thickness]
The first line will calculate the distance to the layer underneath your Line, which should be a Target Point, using After Effects' built-in method. Since our layer is far too wide (for quality reasons we will always scale down but not scale up), we need to divide our value by 100 to be accommodated by the Scale property which ideally goes from 0 to 100 % for our purposes. The second line simply attaches the height to a slider.

For the Rotation property use this:
delta=position-thisComp.layer(index+1).position;
angle=Math.atan2(delta[1], delta[0]);
angle=radiansToDegrees(angle)+180;
[angle]
All this does is target our line towards the Target Point. The 180 (degrees) are only necessary to correct, otherwise our line would point in the opposite direction away from our target.

If you now move around your Target Point and Source Point, the Line will always stay between them and maintain the correct length. That's already useful but not enough for us. All the animation and timing is still missing.


Step 4: All timed out

Our objective was not just to make laying out your map easier but also automate animation as far as possible. That part is still missing and we need to modify our expressions. But let's first think of what we are trying to achieve and how we could do it.

Ideally we don't want to create a single keyframe but still be able to control when our animation starts and how long it lasts. We need After Effects to tell this somehow since it needs a reference to time in order to be able to animate something. To this effect we are going to use the in-point of our layers in the timeline. Also we want our animation to be smooth. Since later on we are going to clone our Line and Target Point a bunch of times, we need to control how fast they spread. If we use a static value it can happen that a short line grows very slowly while a line that needs to cover a larger distance grows very rapidly. This does not look too good and we want to expand our network with a halfway equal velocity for all lines. We need a way to calculate this timing based on the actual length of the line. Lastly we want each Target Point to fade in as the Line approaches it instead of being visible all the time. So let's get to work and figure something out.

Assuming you work on the Scale parameter, you've already added some expressions in an earlier step that look like this:

full_length=length(position-this_comp.layer(index+1).position);
thickness=comp("World Map straight Zoom").layer("Controller").effect("Line Thickness")(Slider); [full_length,thickness]
Now we need to determine how long our Line actually would take to reach its full length if it were growing over time. This value is always somewhere in between the Minimum and Maximum Spread Time. Basically all we are doing here is calculate the difference, correlate it to the layers final length and add that value to the Minimum Spread Time.
spread_time_min=comp("World Map straight Zoom").layer("Controller").effect("Minimum Spread Time")("Slider");
spread_time_max=comp("World Map straight Zoom").layer("Controller").effect("Maximum Spread Time")("Slider");
spread_time_diff=spread_time_max-spread_time_min;
spread_time_real=spread_time_min+spread_time_diff*full_length/10000;
This stuff itself of course doesn't do anything in the way of animation since it only delivers a static value. Again the division by 10000 is necessary to get some usable values 'because our layer is 10000 pixels wide. Let's add some more code to get things going.
out_length=ease(time-inPoint,0,spread_time_real,0,full_length/100);
What are we doing here? Our current length is only dependent from the time passing but there is a chance that our layer doesn't start at time zero. We need to tell this to our expression and compensate for this by subtracting the irrelevant time before the in-point. then we simply compare (or more precisely remap) different values using the ease() method. While time passes, it will look if the composition time (minus the in-point) is within a range between 0 and our calculated spread time. If so, it will slowly increment the length from frame to frame until it reaches its final length at the end of the spread time. That final length we need to divide by 100 because Scale works with proportional values rather than absolute pixel values. All that's left now is modifying our original expression so the last line reads
[out_length,thickness]
This is the basic expression that we are going to modify and apply to other parameters as well. Unfortunately After Effects' expressions only run in local context to the parameter they are applied to, meaning that they completely ignore everything else unless we tell it to look for certain information and also do not send their calculated values to other parameters. In our case this means that we need to calculate the spread times for each parameter again and again since there is no way to store a global variable for that. This makes our code a bit clunky and can slow down your system a bit, but there's no way around it. So once more unto the breach.

Move on to the Target Point and apply the following expression to its Opacity:
full_length=length(position-thisComp.layer(index-1).position);
spread_time_min=comp("World Map straight Zoom").layer("Controller").effect("Minimum Spread Time")("Slider");
spread_time_max=comp("World Map straight Zoom").layer("Controller").effect("Maximum Spread Time")("Slider");
fade_in_time=comp("World Map straight Zoom").layer("Controller").effect("Point Fade in Time")("Slider");
spread_time_diff=spread_time_max-spread_time_min;
spread_time_real=spread_time_min+spread_time_diff*full_length/10000;
real_inPoint=thisComp.layer(index-1).inPoint; out_opacity=ease(time-real_inPoint,spread_time_real,spread_time_real+fade_in_time,0,100); [out_opacity]
At first sight it looks very much like the other expression, but we need to introduce a few changes. First and most importantly we need to reference our time to the spread time of the Line that moves toward the Target Point. This is achieved using the line
real_inPoint=thisComp.layer(index-1).inPoint;
This seems redundant because you naturally could always set the Target Point's in-point to coincide with the Line in-point, but with a lot of layers and in the hectic of a tight deadline it is a stop-gap measure and an easement - you only need to worry about your Line layers. Your Target Point layers will adjust automatically. In addition to this, we also introduce a new parameter called Fade in Time. This is the time it takes to make a Target Point appear after the line has reached its final length.
fade_in_time=comp("World Map straight Zoom").layer("Controller").effect("Point Fade in Time")("Slider");
When we now put all this together, we have this:
out_opacity=ease(time-real_inPoint,spread_time_real,spread_time_real+fade_in_time,0,100);

[out_opacity]
Once more we are comparing the time that is passing but this time only after our Line is already completely drawn by using our calculated spread time and Fade in Time and remap that to animate Opacity from 0 to 100 percent.

Now with all those expressions in place, clone your Line and Target Point layers a few times. Take care to maintain a specific stacking order from top down (Line - Target Point - Line - Target Point and so on). Adjust the Line layers' in-points and place your Target Points and see how your animation looks. Use multiple invisible Source Points to create your network. In my example I used different ones for America, Europe and Asia. Just don't forget to adjust your expressions accordingly.



One of the potentially most dangerous ways of screwing your project is setting the in-points of your layers the wrong way. Obviously After Effects gives you two ways of doing this: Either you simply shift your layer start by pushing your layer in the timeline or you can trim your layer to a new in-point. As long as you don't animate parameters such as Target Point Size and Line Thickness, both methods are usable. Once you start animating those parameters however, just pushing your layers more towards the end of your timeline poses a problem. In this case trimming is the only correct way. Why? Let me explain.

Trimming will maintain all temporal relations in the way we intend it. This is illustrated in the first picture.



If you just slide around your layers in the timeline, After Effects will assume that you also want to shift the animation timing. All animation would still happen, but delayed by the time of the layer in-point. The next picture shows this.



If worse comes to worst, all your layers have a different in-point which further complicates matters and puts all out of sync - at any given point in time you could have a variety of differently sized Target Points or Lines. This is definitely not what you want, so please always use the correct method!!!



Step 5: Animation from outer Space

After you've managed to set up your lines (which admittedly can still be tedious even with all those useful expressions in place), let's have some fun and do something simpler for a change. We are going to zoom in on our network and follow it as it spreads itself across the map. Shouldn't be too difficult, should it? No! But - Stop! There's a big gotcha here.

In After Effects all transformation operations are based on a layer's Anchor Point. Especially with Scale and Rotation this becomes critical. While it's easy to figure out why for rotations, scale escapes most people, so let me explain. Scale is a proportional transformation normally expressed in percent. It is dependent on how far an element is away from the center of the scaling. Since words often don't explain things well enough, simply try this:

1. Import an image and place it into a new composition.
2. Set the Anchor Point to its top left edge (0,0) and compensate for that by adjusting the Position.

3. Look now closely at the edge farthest away from your anchor point and use the Scale parameter. You will see that the change in absolute pixels is quite dramatic - even if you only change it by 1 %, the amount of background hidden or revealed is noticeable.

4. Now move your Anchor Point more toward the bottom right edge. Adjust Position once again.

5. Change the Scale values again and watch your edge. You will see all changes becoming less dramatic, the closer the anchor point gets.

6. Now animate the Position property along with the Scale and Anchor Point. You will find that it is quite difficult to do this and still create a nice looking animation.

So okay, we know it's going to be difficult and we need some way to perfectly control Scale and Position, but how do we do that? The answer is simple: Use less parameters and get more out of it! We have seen that the Anchor Point also effects the Position, so we don't really need to animate the latter. To our advantage we only have one layer that is quite big and offering enough "flesh" at the edges plus it doesn't need to be matched up with other elements anymore at this point. But the next problem awaits: Anchor Points (seemingly) don't have motion paths, so how the hell do you animate and tweak them? That one is simple, too.

First off we are going to set a few keyframes using the parameter sliders or the pan-behind tool. Pick some representative times and follow your lines as they grow. If you now play back your animation, you will see some rough position changes of your map that give you a general idea of the final movement. In order to refine this, all we need to do is open up the layer view by double-clicking on our map in the timeline. Then select Anchor Point Path from the little dropdown in the right-hand corner. A motion path should be drawn immediately and give you all the familiar handles to adjust it. Et voilà - you're almost there! All that is now left to do is create a few keyframes for the Scale parameter to give the illusion of zooming-in and adjust them to match up with the movement.


Step 6: Variations on a theme

Quite often you will not want to limit yourself to straight lines for reasons of design. Of course this technique is also applicable to other parameters. In the project file you will find an example with bendy lines created using masks and the Stroke effect. In this particular example you will also see the limitations of this approach: Unfortunately in After Effects there is no way to access masks from expressions without third-party plugins. This means there is no way for us to determine the exact length of the path/ mask. Without that knowledge we can forego all our timing calculations and use the same value for all strokes. That's not the best that can happen, but for the time being we' can't help it - worse comes to worse and the only two plugins I know that could help here, Bresnev Shu's Expression Effects and Profound Effects' Useful Things, are no longer publicly available. Anyway, it would require heavy code and admittedly I haven't really given the matter much thought.

You should also study ways to change the appearance of your maps to more abstract shapes. In my example I used several effects including Obvious FX Erodilation (download it at www.obviousfx.com, it's free) to create a rounded look. This can sometimes save the day for you if you are stuck with insufficient low-res maps or want to turn your presentation into something special. There's a million more ways of doing it, so keep trying.


Feel free to ask questions regarding this tutorial in the After Effects forum at Creativecow.net


Please visit our forums at Creativecow.net if you found this page from a direct link.



Related Articles / Tutorials:
Adobe After Effects
Imagineer mocha Pro 5 Plug-In for Adobe: An In Depth Review

Imagineer mocha Pro 5 Plug-In for Adobe: An In Depth Review

Imagineer mocha Pro 5 Plug-in for Adobe brings all the amazing features of the professional version of the mocha Planar Tracker directly into After Effects and Premiere Pro in the form of a plugin. In this in-depth review, After Effects tutorial guru Tobias Gleissenberger of Surfaced Studio will show you what you can do with this new plug-in, and discuss what he likes and doesn't like about the new update.

Tutorial
Tobias Gleissenberger
Adobe After Effects
After Effects 2015.3 - My Favorite Features

After Effects 2015.3 - My Favorite Features

Learn why you should upgrade to After Effects CC 2015.3 - 13.8.1 - a close and detailed look at the latest release of After Effects (August 2016). Roei Tzoref will be focusing on his favorite features that set this release apart from previous versions: Performance, Queue in AME, Lumetri Color new features, and more.

Tutorial
Roei Tzoref
Adobe After Effects
Advanced Masking in Adobe After Effects

Advanced Masking in Adobe After Effects

Some of the coolest stuff you can do inside of Adobe After Effects is only possible once you unlock the power of masks. Join After Effects whiz Tobias Gleissenberger of Surfaced Studio to learn about mask animation and interpolation, using the variable width feathering tool, managing mask modes and ordering, and more.

Tutorial
Tobias Gleissenberger
Adobe After Effects
Fixing Common After Effects Problems and Mistakes

Fixing Common After Effects Problems and Mistakes

Got problems using Adobe After Effects? Exported files too large, Expressions not working, mixing shapes and makes, modes/switches, selecting previews for layers vs. comps - Surfaced Studio's Tobias Gleissenberger shows you fast fixes for these and more!

Tutorial
Tobias Gleissenberger
Adobe After Effects
mocha AE Planar Tracker for Absolute Beginners

mocha AE Planar Tracker for Absolute Beginners

Want to learn how to create advanced visual effects? Learn how to use mocha AE to track your shot and add advanced visual effects to live action footage inside Adobe After Effects. mocha can help you track shots that would be hard to track using traditional 2D point or feature trackers because it is a PLANAR TRACKER. A planar tracker uses planes and textures to track as opposed to points or groups of pixels. This allows the tracker to stay on track even if your shot contains motion blur or a very shallow depth of field. mocha AE comes included with Adobe After Effects and is available since CS3 and there is no reason for you not to use this awesome tool to make it easier for you to track your shot, replace screens or rotoscope!

Tutorial
Tobias Gleissenberger
Adobe After Effects
How to Make After Effects Faster with Proxies

How to Make After Effects Faster with Proxies

Learn how to make Adobe After Effects faster by using PROXIES! A proxy is a placeholder that stands in place for a very large video file or image sequence in your project. You can easily create proxies for the large source files that you are using and After Effects will automatically link them to the item in your project panel.

Tutorial
Tobias Gleissenberger
Adobe After Effects
Stabilize & Smooth: mocha 5 Plug-in for Adobe & Avid

Stabilize & Smooth: mocha 5 Plug-in for Adobe & Avid

Imagineer Systems and Boris FX product specialist Mary Poplin shows you how to stabilize with the new mocha Pro 5 plug-in inside of Avid Media Composer, Adobe Premiere Pro and After Effects. This tutorial covers artistic stabilization, such as smoothing out camera movements or stabilizing around moving objects, completely locking down shots, and automatically replacing edge fill on planar backgrounds.

Tutorial
Mary Poplin
Adobe After Effects
Adobe After Effects Puppet Tool

Adobe After Effects Puppet Tool

Become a puppet master by learning how to use the Puppet Tool in Adobe After Effects! This intermediate-level tutorial from After Effects guru Tobias will show you how the Puppet Tool allows you to add joints and animations to bring life to any static image!

Tutorial
Tobias Gleissenberger
Adobe After Effects
How to Spawn A Clone in Adobe After Effects

How to Spawn A Clone in Adobe After Effects

Want to learn how to create a cool clone spawn effect in Adobe After Effects? Follow along with After Effects whiz Tobias from Surfaced Studio in this exciting new visual effects tutorial that combines green screen using Keylight, CC Vector Blur, the Liquefy Effect, CC Particle World, and much more, delivered in Tobias' inimitable style!

Tutorial
Tobias Gleissenberger
Adobe After Effects
Creating A Flame on Your Finger with After Effects

Creating A Flame on Your Finger with After Effects

It is easy to do some motion tracking and attach a basic stock footage element of fire onto your hands, but there is a little bit of work involved if you actually want to make it look good. In this intermediate tutorial by After Effects expert Tobias, you'll see how to use a fire stock footage element to set your thumb on fire! There are lots of useful tricks for null objects, expressions, and more in this tutorial that will help you create all sorts of other cool visual effects -- or set even more things on fire!

Tutorial
Tobias Gleissenberger
MORE
© 2016 CreativeCOW.net All Rights Reserved
[TOP]