Category Archives: Tutorial

Color Wheel

Manipulating shapes and colors using expressions

Download the After Effects project with the code!

Icon

color wheel article

Download

Introduction

As an exercise to practice our expression coding skills, we would like to create a color wheel using a single shape layer and expressions. The wheel should be made with colored arcs of varying hue, saturation and lightness. We want 4 levels of tint and 12 arcs per level (subdivisions). The following figure shows the different parts of the wheel and the notation we’ll use in the expressions:

Structure of the wheel

Constructing The Base Arc

We want to create an initial arc, add expressions to it, and then duplicate that arc to construct the entire wheel. The setup consists of a shape group containing a trimmed stroked ellipse:

Setup for the base arc

Since the wheel is made of concentric circles, the size of each circle depends on the level. We apply the following expression to the ellipse size:

subdivs = 12;
idx = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1]) - 1;
levelIdx = Math.floor(idx / subdivs);
strokeW = content("Arc " + (idx + 1)).content("Stroke 1").strokeWidth;
diam = 0.8 * thisComp.height - levelIdx * 2 * strokeW;
[diam,diam];

We add the following expression to the start property of the Trim Paths effector:

subdivs = 12;
idx = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1]) - 1;
arcIdx = idx % subdivs;
arcIdx * (100 / subdivs);

The expression is the same for the end property, except the last line:

...
(arcIdx + 1) * (100 / subdivs);

The stroke width is set to 10% of the comp height:

0.1 * thisComp.height;

And finally we apply the following expression to the stroke color:

subdivs = 12;
numLevels = 4;
idx = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1]) - 1;
levelIdx = Math.floor(idx / subdivs);
arcIdx = idx % subdivs;
h = arcIdx / subdivs; // hue
s = 1 - levelIdx / numLevels; // saturation (from high to low)
l = linear(levelIdx, 0, numLevels-1, 0.5, 0.3); // lightness (remap range)
a = 1; // alpha (doesn't affect the result here)
hslToRgb([h,s,l,a]);

This should produce something like this:

Structure of the wheel

Duplicating The Base Arc

Quite a lot of code for drawing a simple arc, but now comes the fun part. We simply press Ctrl+D (Cmd+D on Mac) to duplicate the base arc until the wheel is complete:

Duplicating the base arc

When the number of arcs reaches 48 (i.e., 4 x 12), the wheel is complete:ession to the ellipse size:

The complete wheel

Reveal Animation

As a bonus we would like to animate the construction of the wheel. To this end, we add a second Trim Paths effector to the base arc (don’t forget to remove every other arc):

Adding a second trim to the base arc

We add the following trim end expression to sequentially reveal the arcs with a short delay:

arcRevealDur = 8; // duration in frames
delay = 2; // delay in frames
subdivs = 12;
numLevels = 4;
totalArcs = numLevels * subdivs;
idx = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1]) - 1;
startT = idx * delay * thisComp.frameDuration;
endT = startT + arcRevealDur * thisComp.frameDuration;
linear(time, startT, endT, 0, 100);

The expression is the same for the out tangent except the vector points in the opposite direction:

Revealing the wheel

Conclusion

Through this little exercise we have seen how we can manipulate shapes and colors using simple expressions. Hope you find it useful!

You can also check ConnectLayers PRO, a tool that create lines that are dynamically linked to the layers using powerful path expressions. No keyframes at all!

3D Projection

Creating and projecting a 3D cube onto a shape layer using expressions

Introduction

In this exercise we would like to create a 3D spinning cube and project it onto a 2D plane. All of that using a single shape layer and expressions.

This is a port of Daniel Shiffman’s Coding Challenge #112 (code for Processing).

Download the After Effects project with the code!

Icon

3D projection

Download

Setup

We want to draw the cube vertices with filled ellipses, and connect them with thin stroked lines. We would like to create a single point, apply an expression to its position, and then duplicate that point to create the other points. Once all points are created, we will draw the edges.

Creating the first vertex

Math Utils

Manipulating 3D vectors (rotation, projection) is easier with matrices. Since there aren’t any built-in matrix utilities in the expression language, we must create our own. To avoid having a too long expression, we decide to put our matrix code in an external js file (e.g., “matrix.js”). This file can be imported into our our expression at runtime.

We only need basic stuff here: multiply a matrix and a vector, multiply two matrices… Here is our matrix library:

function vecToMatrix(v)
{
   var m = [];
   for (var i = 0; i < 3; i++)
   {
      m[i] = [];
   }
   m[0][0] = v[0];
   m[1][0] = v[1];
   m[2][0] = v[2];
   return m;
}

function matrixToVec(m)
{
   return [m[0][0], m[1][0], m.length > 2 ? m[2][0] : 0];
}

function matMatMul(a, b)
{
   var colsA = a[0].length;
   var rowsA = a.length;
   var colsB = b[0].length;
   var rowsB = b.length;
   var result = [];
   for (var j = 0; j < rowsA; j++)
   {
      result[j] = [];
      for (var i = 0; i < colsB; i++)
      {
         var sum = 0;
         for (var n = 0; n < colsA; n++)
         {
            sum += a[j][n] * b[n][i];
         }
         result[j][i] = sum;
      }
   }
   return result;
}

function matVecMul(a, v)
{
   var m = vecToMatrix(v);
   var r = matMatMul(a, m);
   return matrixToVec(r);
}

Creating The Vertices

First we need to import the matrix lib (“matrix.js”) into our ellipse position expression. This is done with the following line of code:

$.evalFile("F:/Documents/JSX/matrix.js");

Then we set some design variables and retrieve the index of the cube vertex:

r = 200; // cube size
distance = 2; // affects perspective
rotSpeed = 0.06; // in radians per frame

idx = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1]) - 1;

We need to determine the location of each vertex from its index. To do that we can use the following formula (taken from math.stackexchange):

p = []; // 3D vertex position at start
bs = [];
for (i = 0; i < 3; i++)
{
	bs[i] = (idx >> i) & 1;
	p[i] = 0.5 * Math.pow(-1, bs[i]);
}

Note that the above formula will position the vertices in the following order (front face: 1-2-4-3, back face: 5-6-8-7):

Traveling along the path

Now that we have found the 3D starting position of the vertices, we can dive into the main part of this exercise. We basically loop through every previous frame, setup rotation matrices based on the current angle, apply 3 successive rotations (around Y, X, and Z axis), and finally project the 3D vertex to find its 2D position inside the shape layer. Here is the beast:

angle = 0;
for (t = 0; t <= time; t += thisComp.frameDuration)
{
	// rotation matrices (https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations)
	rxMatrix = [[1,0,0], [0,Math.cos(angle),-Math.sin(angle)], [0,Math.sin(angle),Math.cos(angle)]];
	ryMatrix = [[Math.cos(angle),0,-Math.sin(angle)], [0,1,0], [Math.sin(angle),0,Math.cos(angle)]];
	rzMatrix = [[Math.cos(angle),-Math.sin(angle),0], [Math.sin(angle),Math.cos(angle),0], [0,0,1]];

	// do rotations (the order matters, here we chose it arbitrarily)
	p3d = matVecMul(ryMatrix, p);
	p3d = matVecMul(rxMatrix, p3d);
	p3d = matVecMul(rzMatrix, p3d);

	// increase rotation angle
	angle += rotSpeed;
}
// handle perspective
z = 1 / (distance - p3d[2]);

// project 3D point
projectionMatrix = [[z, 0, 0], [0, z, 0]];
p2d = matVecMul(projectionMatrix, p3d);

// scale result
mul(p2d, r);

To create the cube vertices we just need to duplicate the first Ellipse group 7 times.

Duplicating the first vertex

We obtain the following animation:

Animating the vertices

Great, our calculations seem correct. Now we need to connect those dots to finish the cube.

Creating The Edges

Since we cannot connect all vertices with a single path, we need to create multiple connecting lines. We want these lines to be constructed from the same unique expression, and control the connected vertices by specifying their indices in the shape’s group name.

Here is the first connecting path which connects the first four vertices (i.e., the front face):

Creating the first connecting path
Edges of the front face

We apply the following expression to the path property of the connection:

indices = thisProperty.propertyGroup(3).name.split("Connection ")[1].split(" ");
pts = [];
for (i = 0; i < indices.length; i++)
{
	idx = indices[i];
	pt = content("Ellipse " + idx).content("Ellipse Path 1").position;
	pts.push(pt);
}
createPath(pts, [], [], false);

For creating every other connection we duplicate the first connection and rename it with the appropriate indices list for that connection. The final timeline looks like this:

Final timeline

It’s time to press the 0 key on the numpad to preview the final animation.

Spinning cube projected onto a shape layer

Conclusion

In this exercise we have shown how to project a 3D object onto a 2D plane using expressions. We have created our own matrix library to facilitate 3D calculations, and imported it into our expression. We used it to setup and manipulate rotation and projection matrices. Hope you find it useful!

You can also check ConnectLayers PRO, a tool that create lines that are dynamically linked to the layers using powerful path expressions. No keyframes at all!

Tutorial: Textless effect

Remember the amazing “Textless” short by Gareth Smith & Jenny Lee?
Well, here’s our own tutorial that recreates the workflow to achieve this amazing effect where the content of a sign is falling drove by physics.
We are going to use Adobe After Effects, Mocha AE to track the sign and Newton3 for the physic simulation. Adobe Illustrator to vectorize the artwork and Adobe Photoshop to clean up the sign using the content aware tool.
That’s a lot of tools for an amazing result. But don’t worry, everything is going to be quite easy to do.

“Textless” by Gareth Smith & Jenny

If you need more in depth about the tracking with Mocha AE, check the great tutorial of Mark Christiansen at School Of Motion:

Get Newton for Adobe After Effects: https://aescripts.com/newton/

Link to the video used in this tutorial .

Get Rift for Adobe After Effects: https://aescripts.com/rift/

Music: Otis McDonald.

Want to ask something? Contact us!

Tutorial: Fill-Mix-Flush using Newton3

Here’s a new tutorial for Newton3, the physics engine for Adobe After Effects!

In this classic case of animation which uses physics intensely, you’ll learn how to fill a shape, turn it to a washing machine then drain it.
Import animated objects into Newton3.
Add and remove objects from your simulation.
Fine tweak your simulation to get the best result!
We’ll also show you how to use our tool Solidity to colorize hundreds of objects easily!

Get Newton3 and Solidity (part of the set “LayerGenerator”) !

Want to ask something? Contact us!

Interview(s)!

Our friends from Motion Café invited us on their show to talk about our history, our products and do some demos. Finally, we had so much to say that we did 2 shows!
In the first we talked a lot about our history and Newton. Valentin was able to come back to the genesis of this product, show a little moment of history with the first video made with it and also the first version of our tool. We also have show more technical things as well as tips.

(Video is in french but you can use the subtitles option to translate it)

In the second show, we came back to Newton and in particular to the (new) skater’s setup. We then talked about Pastiche and LayerGenerator with new features, and we ended with a little tour of ConnectLayersPRO!

You can find these videos on the Motion Café Youtube channel.

Tutorial: Create a flock of birds

Sara contacted us asking if Pastiche for Adobe After Effects would be able to create a flock of birds in order to form a final logo.

And here’s our answer… 🙂

We’ll show you step by step how to setup this project to quickly get a result. Remember, those are not particules but individual layers! Everything is keyframed by our tools Pastiche! We’ll also us LayerGenerators

Get Pastiche and LayerGenerators: aescripts.com/pastiche

Want to ask something? Contact us!

Another exemple of a flock of birds using Pastiche.

Tutorial : Balloons with Newton2

Tutorial : Balloons with Newton2

The final product:

Music: “Against My Will” by The Fisherman

You can download the AEP with Newton2’s settings (CS6 and above) here.

In this example, I wanted to illustrate the Gravity Scale feature in Newton2, and how we can use it to simulate flying balloons that interact with their environment.
Gravity Scale allows you to set a custom gravity per body.
I’ve used Connect Layers to represent the ropes attached to the balloons.

There’s no “Flying in the air” option in Newton, but you can somehow make objects fly if you use a negative Gravity Scale value!

balloons gravity scale

You need to tweak some parameters to make it look correct: for instance, balloons have lower density and higher bounciness coefficient. I’ve also increased the Linear Damping value to fake air resistance.

balloons_settings

To add a sense of depth in the animation, I’ve used the Collision Group feature: the pink and green balloons collide with each other, but ignore the orange balloon. The little squares that simulate the ropes can only collide with the walls.

balloons_cg

I’ve animated the hand graphics using AE’s Motion Sketch. I wanted the ropes to start from a unique point, but animated freely when the hand releases them. I’ve simply parented the start point of 2 ropes to the animated one. Then in Newton, I’ve chosen the Kinematic body type for all start points. At the end of keyframes animation, when bodies become dynamic, ropes move independently!

balloons_parenting

Creating the ropes was made easy by the use of the Rope feature of Connect Layers. You just need to select the reference objects, and hit Rope.

balloons Connect Layers

 

One common mistake is to forget to place the anchor point of your objects to the desire place, where the rope must pass through. You usually think about this after creating the keyframes in Newton. To solve this, create a null object, place it appropriately, and parent it to the reference object. Then choose the null instead of the reference object for creating the rope.

balloons null connect layers

Download test scene

Icon

3Balloons

Download

BLOG

[ess_grid alias=”blog”]

Create Soft body using Newton2 and Connect Layers.

Some more experimentations on creating soft body using Newton2 and Connect Layers….

Inspired by the work of Lok Fu, we conducted some tests to create soft bodies using Connect Layers (for another technique that makes use of the puppet tool, see the tutorial from ‘Tercel’).

 

The final product:

music : Robgroove – Mashed up walking home in the dark // www.RobGroove.com

You can download the AEP (CS6 and above) and Newton2 settings file

Icon

Newton2 Soft Bodies demo aep

Download

The basic idea is to create the outline of the soft body with simple objects (e.g., box, circle), and connect them with soft joints.
Make sure that the anchor point of these objects are layer-centered.
We set up different joint rigs in Newton that create different behaviors for the soft bodies.

The first circle behaves like a bubble. We created a circular chain of distance and piston joints.

newton_-_soft_bodies_-_circle

The second one resembles to a soft ball. We used a circular chain of pivot joints, and distance joints as spokes.

newton_-_soft_bodies_-_spokes

And don’t forget to rise the Sub-steps value in the Solver panel to produces a more accurate simulation!

Newton_-_soft_bodies_-_substeps

Finally, the key is to activate the “closed” rope feature in Connect Layers.

connect_layers_options

Newton_-_soft_bodies_-_rope

Newton tutorial : Design by Apple

Newton tutorial : Design by Apple

Here’s a great tutorial by Lloyd from aescripts that shows how to use Newton to create the physics simulation sections of the “Designed by Apple” spot created by Buck.

The very interesting part is that Lloyd use AEmatic body type to define a certain type of animation but with a kind of physics inside. Pretty cool. Thanks Lloyd!

BLOG

[ess_grid alias=”blog”]