11 Vector Animation Techniques using After Effects Expressions
Published on 10 July 2024
Introduction
Vector animation means animating graphic elements in your explainer video.
Though there are many different AI tools online popping up every day, professional, industry standard compositing programs like After Effects and Fusion still do enjoy most popularity among the CG artists and digital studios.
If one reason behind it could be the nascent state of the AI tools and their limited features, mostly offered in their free versions, the other reasons could be the availability of huge pool of online templates and the expertise of the CG artists using these programs attained over decades.
Even to create such simple animation quick and easy for showcasing your portfolio, you need to master a few tricks and techniques.
And Adobe After Effects is still the best choice for creating animated explainers for online marketing. In this piece, we’ll see different instances of vector animations and analyze how to do these animations inside After Effects with the help of Expressions.
Just in case, you’re not much familiar with the use of expressions animating graphic elements for creating explainer videos, you can have a quick look at couple of my previous articles, especially on the After Effects Expressions. The links are given below.
- 16 After Effects Expressions with Math Operators [JavaScript]
- Useful After Effects Expressions – Random Patterns with Scripts
In this article, we’ll focus on how to use various shapes with different tricks inside After Effects with an instance-based approach. In plain language we’ll see an animation and then analyze its breakdowns.
Now before I start take a plunge, let me acknowledge some of the gurus in the field of After Effects Expressions who continue to inspire people like us. Apart from, Andrew Kramer and Dan Ebberts, they are Michael Natkin, Fred Lewis, Brian Maffitt & Steve Holmes of Total Training.
It’s rather a compilation, which is always helpful.
Table of Contents
1. Vector Animation in After Effects – Example 1: Circular Motion around a layer
- Create a Circle
- Add three Expression controllers on the Circle; Two Slider Controllers (Effect > Expression Control > Slider Control) and one Point Control (Effect > Expression Control > Point Control)
- Name the Slider Controls as Radius and Cycle inputs
- Add the following expression in the Position property of the Circle
radius = 275; // the radius of the circle
cycle = 0.8; // number of seconds to complete a circle; higher value = slower
if(cycle ==0){cycle = 0.001;} //avoids a "divide by zero" error
phase = 30; // initial angle in degrees from bottom
reverse = 1; // 1 for ccw, -1 for cw
x = Math.sin( reverse * degrees_to_radians(time * 360 / cycle + phase));
y = Math.cos(degrees_to_radians(time * 360 / cycle + phase));
add(mul(radius, [x, y]), position)
I have duplicated the first circle and changed the ‘reverse into -1’ for the clockwise rotation in the position expression of the second circle.
2. Circular Motion around a layer
3. Noise in Wiggle ! What’s that?
We all know wiggle expression, in fact that’s the expression we often begin with. Noise is the jittery motion that changes the quality of the wiggle. Let’s see with one instance.
- Create a circle and add the following expression to the position property of the Circle
p = 2; //wiggle frequency
q = 100; //wiggle amount
r = 10; //detail of noise, lower is smoother
wiggle(p, q, r)
- Now, create another circle or make a copy of the first and assign r = 1.
- Higher the detail of the noise more jittery is the motion and lower the number much smoother the wiggle. Below is the expression I have added to position property of the second circle (in the right)
- The thumb rule is higher the detail of the noise or the value of ‘r’, the less jittery the movement is, while a lower number of ‘r’ yields a much smoother wiggle.
p = 2; //wiggle frequency
q = 100; //wiggle amount
r = 1; //detail of noise, lower is smoother
wiggle(p, q, r)
4. Wiggle in Y and Z axis separately – with noise
What’s exactly happening here! You made two circles, with BG as usual.
Expression for the Wiggle in Y Axis
wigfreq = 5; //wiggle frequency
wigangle = 100; //wiggle amplitude
wignoise = 3; //amount of noise
make = wiggle(wigfreq, wigangle, wignoise);
[position[0], make[1]] //will wiggle just on Y
Expression for the Wiggle in Z Axis – Make sure You have already made this layer 3D
wigfreq = 10; //wiggle frequency
wigangle = 100; //wiggle amplitude
wignoise = 3; //amount of noise
make = wiggle(wigfreq, wigangle, wignoise);
[position[0], position[1], make[2]] //will wiggle just on Z
In After Effects Expressions, position dimension or axis X, Y and Z are denoted as [0] , [1] and [2]. Let’s move to the next one.
5. Oscillation in two dimensions – Simple Harmonic Motion!
Pretty easy.
- Create a box and a background, as usual.
- For linear interpolation of oscillation, put the following expression in the position property (Alt+click over the stop watch)
from = [300, 350]; //one end of your oscillation
to = [1600,350]; //the other end of your oscillation
period = 1.5; //time between oscillation points (multiply by 2 for a round trip)
t = time % (period * 2);
if (t > period) t = 2 * period - t;
linear(t, 0, period, from, to)
This code is for the box at the top. The linear interpolation is evident. Let’s now assign the following piece of code at the position property of the box at the bottom.
from = [300, 850]; //one end of your oscillation
to = [1600,850]; //the other end of your oscillation
period = 1.5; //time between oscillation points (multiply by 2 for a round trip)
t = time % (period * 2);
if (t > period) t = 2 * period - t;
ease(t, 0, period, from, to)
Clearly, you change the positional values at ‘from’ and ‘to’ to reposition the boxes and the period to change the time period of oscillations. Actually, those are amplitude and frequency of an oscillation.
6. Oscillate Rotation with Linear and Ease (smooth) interpolation
Linear Interpolation
from = -60; //one end of your oscillation
to = 60; //the other end of your oscillation
period = 1; //time between oscillation points (multiply by 2 for a round trip)
t = time % (period * 2);
if (t > period) t = 2 * period - t;
linear(t, 0, period, from, to)
Ease Interpolation
from = -60; //one end of your oscillation
to = 60; //the other end of your oscillation
period = 1; //time between oscillation points (multiply by 2 for a round trip)
t = time % (period * 2);
if (t > period) t = 2 * period - t;
ease(t, 0, period, from, to)
Oscillations are an integral part of the vector animation and they are hard to achieve without the After Effects Expressions. And these vector animation techniques in explainer videos will surely save a lot of time if you want to implement your ideas quick and fast.
7. Bounce to a Surface from an Apogee (apex)
Apogee means the the maximum distance from a central point, in this case the surface. You can think of a satellite at its max distance from a planet while orbiting. That’s the apogee of that satellite. Let’s now see this vector animation first and then we’ll see the code.
Add the following expression to the position property of the box. Change Linear to Ease for a smoother animation.
surface = [600, 800]; //the position of the "bounce" surface
apogee = [600, 250]; //the "apogee" of the bounce
period = 1.5; //the length of time from surface to apogee
t = time % (period * 2);
if (t > period) t = 2 * period - t;
linear(Math.sin(t * Math.PI / period), 0, 1, surface, apogee)
Clearly, you can adjust the Surface and Apogee according to the need in your vector motion graphics. Now, change the linear into ease and you’ll get to an animation as in the right.
surface = [1500, 800]; //the position of the "bounce" surface
apogee = [1500, 250]; //the "apogee" of the bounce
period = 1.5; //the length of time from surface to apogee
t = time % (period * 2);
if (t > period) t = 2 * period - t;
ease(Math.sin(t * Math.PI / period), 0, 1, surface, apogee)
If you want to add a decay to the bounce while creating the animation, you should have a different approach.
8. Control the frequencies of a Watch Hand – Expression and using Slider Controls
This time we’ll use After Effects Expressions for osculating the stop watch hand. I have made a simple skeletal structure of a watch dial outline and a single hand. The idea is to oscillate the hand and control its frequency, first using an expression and then adding one slider control. Let’s first see the animation.
- Create a circular outline as the dial of the watch and a single hand. Set the anchor point of the hand at its fulcrum about which it would rotate.
- Add the following expression to the rotation property of hand layer to make it oscillate.
freq = 1;
amp = 100;
value + amp*Math.sin(freq*time*Math.PI*2)
We can also have a look at post expression graph of the code. It’s a simple sine wave and that obvious. But what if you want to
further control this vector animation to speed up or down the movement of the hand?
9. A good way to understand the use of Slider Control over an After Effects Expression
Honestly, the use of different expression controls, slider, points, angles and others often makes us, especially the newbies, dither going ahead with them. Why the hell should we use them when the expressions are already there in the first place!
The thing is, with the expression we have brought in additional functionalities to a certain property of a layer. Now slider controls help us add keyframes to manipulate those movement further in terms of controlling their speed and thereby adding a finer touch to the vector animation in question.
Let’s now analyze the second animation in the above movie i.e. in the right and then understand the procedure.
- Apply Effect > Expression Controls > Slider Controls
- Apply the following code to the rotation property of the Hand layer
freq = effect("Slider Control")("Slider");
amp = 100;
value + amp*Math.sin(freq*time*Math.PI*2)
Now, I have added 2 as the value for Slider control added as an expression slider over the hand layer i.e. the layer with the watch hand oscillating.
But this is a uniform value, 2, and that’s why the expression graph shows similar wax and wane, typical of a sine wave, with a much crests and abysses. We can further tweak this to attain an irregular pattern.
- I have added a few values for the keyframes at the slider control applied on the hand layer.
- The post expression graph clearly shows the variations in the accelerated, then uniform and then again somewhat accelerated movement of the hand.
- In a nutshell, we have added the oscillation as the base function with expression and then controlled that with slider control keyframes.
I have simply added different values of keyframes, held them and changed to another value.
10. Some more variations for oscillating watch hand – wiggly rotation and speed control
The code for the left hand side ‘hand’.
freq = effect("Slider Control")("Slider");
amp = 40;
n = freq.numKeys;
if (n > 0 && freq.key(1).time < time){
accum = freq.key(1).value*(freq.key(1).time - inPoint);
for (i = 2; i <= n; i++){
if (freq.key(i).time > time) break;
k1 = freq.key(i-1);
k2 = freq.key(i);
accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
}
accum += (freq.value + freq.key(i-1).value)*(time - freq.key(i-1).time)/2;
}else{
accum = freq.value*(time - inPoint);
}
wiggle(accum,amp)
I have used a value of 0.5 as the freq in Slider control throughout. Let’s now see the code for the second watch hand, i.e. in the right.
freq = effect("Slider Control")("Slider");
amp = 100;
n = freq.numKeys;
if (n > 0 && freq.key(1).time < time){
accum = freq.key(1).value*(freq.key(1).time - inPoint);
for (i = 2; i <= n; i++){
if (freq.key(i).time > time) break;
k1 = freq.key(i-1);
k2 = freq.key(i);
accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
}
accum += (freq.value + freq.key(i-1).value)*(time - freq.key(i-1).time)/2;
}else{
accum = freq.value*(time - inPoint);
}
value + amp*Math.sin(accum*Math.PI*2)
In this case, I have used several values, held some of them, changed to the next over the period of time. Similar animations with a different set of codes.
11. Variation in Wiggly oscillations with different arguments – Randomization of vector animation without using Random Expressions
This is the last instance in this segment. We’ll see both the animations first and then go through the codes.
See the video and let’s first see the code for the ‘hand’ in the left. Remember, they’re to be applied in the rotation property.
freq = effect("Slider Control")("Slider");
amp = 10;
n = freq.numKeys;
if (n > 0 && freq.key(1).time < time){
accum = freq.key(1).value*(freq.key(1).time - inPoint);
for (i = 2; i <= n; i++){
if (freq.key(i).time > time) break;
k1 = freq.key(i-1);
k2 = freq.key(i);
accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
}
accum += (freq.value + freq.key(i-1).value)*(time - freq.key(i-1).time)/2;
}else{
accum = freq.value*(time - inPoint);
}
wiggle(accum,amp)
See, in the last line the wiggle function has two arguments. Now let’s go through the expressions.
freq = effect("Slider Control")("Slider");
amp = 10;
n = freq.numKeys;
if (n > 0 && freq.key(1).time < time){
accum = freq.key(1).value*(freq.key(1).time - inPoint);
for (i = 2; i <= n; i++){
if (freq.key(i).time > time) break;
k1 = freq.key(i-1);
k2 = freq.key(i);
accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
}
accum += (freq.value + freq.key(i-1).value)*(time - freq.key(i-1).time)/2;
}else{
accum = freq.value*(time - inPoint);
}
wiggle(1,amp,1,.5,accum)
I have maintained a value of 2 for the slider control for both the cases. Amplitude is same too, 10 for both the hands. The only difference made in the wiggly oscillation is due to the wiggle function in terms of the arguments, which are different in two cases.
Note that, wiggle in After Effects Expression can take up to five arguments.
Conclusion
Vector animation is an integral part of CG videos for quite some time. And it’s important that we know some quick and easy techniques for creating vector motion graphics.
Here I have compiled a few expressions with some videos for our convenience, especially for those who are not particularly geeky and somewhat do avoid using codes.
But this piece, I have written in such a way, that you, even without an iota of exposure in to programing could just take up the code and use it wherever you find it suitable.
Helping to create vector animation using After Effects and it pool of expressions is what the sole objective of this article. It’s certainly not over. There will more some pieces to follow where I’ll discuss using some other expressions to yield different types of animation.
Hope you’ll find this article with the vector animation techniques in explainer video useful. I’ll upload the AE file with these expressions for your convenience. So keep a close watch.
Please don’t forget to share this piece. It’ll encourage me write more such content.