Faking the C4D MoGraph Module in After Effects

Ready to get real geeky? In this tutorial you’ll be spending plenty of time getting acquainted with expressions. You’ll be writing all kinds of code (or copying and pasting if that’s more your style) to try and recreate some of the very powerful functions of the Cinema 4D MoGraph Module.

By the end of this tutorial you’ll have a pretty simple rig that will let you do some of the things MoGraph in Cinema 4D is capable of. You can even extend the functionality of the rig a heck of a lot by adding more and more code, but this video will keep it pretty straightforward. The end result is a cool kaliedescope-esque animation that would be almost impossible to achieve without this rig.

Make sure you check out the Resources tab for all of the expressions that were used in this lesson.

If you have any questions, click over to the Q&A tab to post them. Other students can answer you, and we'll put our team on the case to try and get you a solution ASAP.

28_MographAE.zip

Watch the tutorial for instructions on how to use these!

You need a DOT-MASTER layer at the bottom of your comp, and a MOGRAPH-CTRL null with Expression Sliders for Time Offset and Random Time.

Rotation Expression

numDots=thisComp.layer("DOT-MASTER").index-1;

layerRot=360/numDots;

myIndex=thisComp.layer("DOT-MASTER").index-index;

myIndex*layerRot;

Time Remap Expression

timeOffset=thisComp.layer("MOGRAPH-CTRL").effect("TimeOffset (frames)")("Slider")/24;

baseTime=thisComp.layer("DOT-MASTER").timeRemap;

myIndex=thisComp.layer("DOT-MASTER").index-index;

seedRandom(index, true);

randomTimeAmt=thisComp.layer("MOGRAPH-CTRL").effect("RandomTime (frames)")("Slider")/24;

randomActual=random(-randomTimeAmt, randomTimeAmt);

baseTime+(myIndex*timeOffset)+randomActual;

    • Hi! I´m learning "mograph tutorial", but I have trouble with the first expression: "numDots = thisComp.layer..." Where can I get the code"? many thanks! love

    • Hi Barbara, you can find the code on the Resource tab which is on the top-left portion of the lesson page.

    00:00:00,245(high-energy electronic music)
    00:00:16,472- Hello again. Joey here at School of Motion,
    00:00:18,719and welcome to Day 28 of 30 Days of After Effects.
    00:00:21,836Today's video is going to be pretty cool
    00:00:24,121and there's going to be a lot of expressions in it,
    00:00:26,194but in the end what you're gonna end up building
    00:00:28,481is a rig that in many ways resembles
    00:00:30,374MoGraph from Cinema 4D.
    00:00:32,872Motion graphics artists love MoGraph
    00:00:34,982because it lets you do stuff like
    00:00:36,314what's going on behind me
    00:00:37,363with not that many keyframes and minimal effort,
    00:00:40,371and it's easy to tweak.
    00:00:42,030In After Effects, there are some plug-ins
    00:00:43,696that can replicate the MoGraph module,
    00:00:45,971but actually, this is one of the fastest
    00:00:48,374and easiest ways I know
    00:00:49,838to build animations like this.
    00:00:51,806There's a lot of advantages
    00:00:52,874to doing this way that I'm going to talk about.
    00:00:55,052Now, if you're into making repetitive animations,
    00:00:57,782and cool geometric things like this,
    00:00:59,798you're gonna like this video.
    00:01:01,372Don't forget to sign up for a free student account
    00:01:03,398so you can grab the project files
    00:01:05,414and expressions from this lesson,
    00:01:07,267as well as assets from any other lesson on the site.
    00:01:10,024Now let's hop into After Effects and get started.
    00:01:13,492So this one is pretty cool.
    00:01:16,423This is somethin' that I've started doing
    00:01:18,262a little bit more in After Effects,
    00:01:19,562which is tryin' to recreate some of the functionality
    00:01:21,452of Cinema 4D inside of it.
    00:01:24,052For those of you that haven't used Cinema 4D very much,
    00:01:27,355there is this big area of Cinema 4D called MoGraph,
    00:01:30,670which lets you, very easily,
    00:01:33,661make repeating animation like this.
    00:01:37,074Sometimes I call it cascading animation
    00:01:39,125because it's animation that's simple, right,
    00:01:42,164but it's just offset, right.
    00:01:44,197So if you just look at each piece of this,
    00:01:46,226like these little pink balls that fly out of the center,
    00:01:49,646the animation of each one is very simple,
    00:01:51,446but what makes it cool is they're all offset.
    00:01:53,775And look at these triangles,
    00:01:55,354these blue kinda triangles,
    00:01:57,007they're offset too, but in a random way,
    00:01:59,331it's not in this, like, linear way.
    00:02:01,537So I'm gonna show you how to build a system
    00:02:05,262and I gotta warn you,
    00:02:06,095this is an expressions sort of based technique,
    00:02:10,763but it's actually not as complicated as you'd think,
    00:02:12,942and if you're getting into expressions,
    00:02:14,953this is actually a really good technique
    00:02:16,755to try and use as a way to figure out expressions better.
    00:02:20,856So what we're gonna do
    00:02:22,523is we're gonna make a new comp,
    00:02:24,751and we're just gonna call this Dot.
    00:02:28,527So first thing we need to do
    00:02:29,889is create some animation that we can then replicate
    00:02:33,127and create this cool cascading animation with.
    00:02:35,708So let's make a circle,
    00:02:37,389and it's very important
    00:02:38,963because of the way this is gonna work
    00:02:40,320that we are very precise
    00:02:41,801with where we put things on screen.
    00:02:43,241So I want a circle right smack-dab
    00:02:45,860in the middle of the screen.
    00:02:46,780So I'm gonna double-click on this Ellipse tool.
    00:02:49,862And this is a little trick I use
    00:02:51,235because what happens is it will then put an ellipse
    00:02:54,406right in the middle of your frame,
    00:02:56,384right in the middle.
    00:02:57,843And now if I go to the Ellipse path,
    00:03:00,204and I set the size to 1080 by 1080,
    00:03:02,688now it's a perfect circle
    00:03:03,952and now I can shrink it down
    00:03:05,014and now I've got a circle directly in the center
    00:03:08,059and I know for sure that the anchor point
    00:03:10,649is right in the middle.
    00:03:11,815All right, so let's get rid of the stroke,
    00:03:13,298I don't want a stroke on that,
    00:03:14,364I just want a little circle just like that.
    00:03:16,797So let's just do a simple little animation on this.
    00:03:20,943Let's have it,
    00:03:22,848let's have it move
    00:03:24,790from the center
    00:03:25,942out to the right somewhere.
    00:03:26,820So let's separate the dimensions,
    00:03:28,540put a keyframe on X,
    00:03:30,641let's go forward, I don't know,
    00:03:32,84816 frames and scoot way over here,
    00:03:36,070easy easy.
    00:03:37,942And of course we don't just wanna leave it like that,
    00:03:40,265we wanna pop in here
    00:03:41,244and we wanna add a little character to this.
    00:03:42,684So I'm gonna have it,
    00:03:44,808I'm gonna have it overshoot a little bit, okay.
    00:03:47,847So let's have it overshoot and swing back,
    00:03:52,400maybe it overshoots back the other way a little bit,
    00:03:56,988and really we just want something
    00:03:59,401that's gonna have a lot of movement to it,
    00:04:02,334so that when we start cloning it
    00:04:04,679and offsetting the animation,
    00:04:06,725it'll look really interesting.
    00:04:09,390Okay, let's see what this looks like.
    00:04:13,107Cool, nice little animation there, beautiful.
    00:04:16,629And then I don't want the dot to just
    00:04:20,189appear in the middle,
    00:04:21,022I want it to sort of animate on,
    00:04:23,104so let's also animate the scale,
    00:04:25,929and let's just go to like, frame six,
    00:04:30,406make it 100% there,
    00:04:31,715and at frame zero it's zero percent scaled,
    00:04:35,584so now it'll just sort of scale up
    00:04:38,000as it animates on.
    00:04:39,480Piece of cake.
    00:04:40,313All right, so there's our animation.
    00:04:42,535So here's what we're gonna do.
    00:04:44,209Let's now make a new pre-comp,
    00:04:45,515and let's call this Dot_MOGRAPH,
    00:04:50,627and let's bring that Dot animation in there.
    00:04:53,310So what we wanna do,
    00:04:55,224is we wanna be able to duplicate this
    00:04:57,582a bunch of times, right,
    00:04:59,146and have each one
    00:05:02,068be slightly offset, like this, right?
    00:05:05,830And we want them to sort of create
    00:05:09,127this radial kind of array,
    00:05:11,760and then we want each one to be offset in time a little bit,
    00:05:14,873right, so we can get this cool cascading thing.
    00:05:17,845Now, you can do it manually, of course,
    00:05:19,469but that's a pain in the butt,
    00:05:20,990and that's why God created expressions.
    00:05:24,510Or, I don't know, someone at Adobe, it wasn't really God.
    00:05:27,059So let's think about this.
    00:05:29,045What are we gonna need in order to make this happen?
    00:05:32,951Well, for one thing, we're gonna need an expression
    00:05:35,803to automatically rotate our layers for us,
    00:05:38,391so that they are rotated correctly, right?
    00:05:41,949And there's a pretty neat way we're gonna do that.
    00:05:43,961On top of that, we're gonna need an expression
    00:05:46,389to offset the time of these layers for us,
    00:05:50,504and for that we're gonna wanna probably
    00:05:53,137be able to set the delay of each layer ourselves,
    00:05:57,465so we're gonna wanna a control to be able to do that.
    00:06:01,103We also may want these things to animate
    00:06:03,182on kind of using a random time offset
    00:06:06,723instead of having this one be one frame later,
    00:06:10,254this one be one frame later,
    00:06:11,087we may want them to be a little more random,
    00:06:14,881and have random timing.
    00:06:15,714And so we may wanna be able to also set
    00:06:17,664the total randomness.
    00:06:20,766So the rotation can be set automatically
    00:06:24,022based on how many of these dots there are.
    00:06:25,964If there's two dots then this one needs
    00:06:28,603to be rotated 180 degrees.
    00:06:30,963If there's three dots,
    00:06:32,098well, then this one needs to be rotated 120 degrees
    00:06:35,118and this one needs to be rotated 240 degrees.
    00:06:38,474So we wanna automatically be able to set that stuff.
    00:06:41,886Ok, so, here's what we're gonna do.
    00:06:43,228We're gonna make a null,
    00:06:45,335and we're gonna call this MOGRAPH-CTRL.
    00:06:50,020So this will be our controller object,
    00:06:52,338and we don't need it to be visible.
    00:06:54,296We're gonna add,
    00:06:55,497in the Expression Controls
    00:06:56,330we're gonna add a slider control.
    00:06:58,899We're actually gonna add two slider controls.
    00:07:00,785So the first slider control is gonna be the TimeOffset,
    00:07:05,176and we will have this work in frames, okay.
    00:07:10,508And then I'm gonna duplicate this
    00:07:11,921and we will have a RandomTime in frames.
    00:07:17,921And I wanna be able to set both,
    00:07:19,611so we could have,
    00:07:21,571we could have the animation happen
    00:07:24,353in a cascading fashion,
    00:07:26,043like counter-clockwise or something,
    00:07:28,196but we could also have it be slightly random,
    00:07:30,103I wanna have the ability to do both.
    00:07:32,721So first let's talk about the rotation.
    00:07:35,266So this is gonna depend on having one layer
    00:07:39,009that is sort of our reference point.
    00:07:41,342So what I'm gonna do is I'm gonna duplicate the Dot,
    00:07:44,006so now there's two,
    00:07:45,198I'm gonna make the bottom one a different color,
    00:07:47,537and I'm gonna call this DOT-MASTER.
    00:07:53,832Now this one, I'm gonna rename it to DOT_01.
    00:07:57,632Now it is helpful if you put a number on the end
    00:08:01,092because if you do,
    00:08:02,539when you duplicate this, After Effects
    00:08:04,622will automatically increment the number for you.
    00:08:07,087So that's just like a nice little trick.
    00:08:09,595So we're gonna put an expression on the rotation of DOT_01,
    00:08:13,692and what we need that expression to do is
    00:08:14,974figure out how many dots there are total in the scene,
    00:08:18,733figure out okay, well, there's two dots,
    00:08:20,823so how much do I need to rotate
    00:08:24,339this dot so that it will create a 360 degree circle?
    00:08:29,729So let's talk about how we're gonna do this.
    00:08:31,847Here's our expression.
    00:08:32,998Hold Option, click the stopwatch,
    00:08:34,478now you can enter an expression.
    00:08:35,607So we first need to know how many dots
    00:08:38,354are there total in the scene.
    00:08:41,457Okay, now how can we figure that out?
    00:08:43,976Every layer in After Effects has an index,
    00:08:46,074that's this number right here in this column,
    00:08:49,359so if we know that the master layer,
    00:08:54,587whatever layer's at the bottom here
    00:08:56,391that we're basing a lot of information off of,
    00:08:59,334we can look at the index of that layer,
    00:09:01,703because that's always gonna be the biggest number.
    00:09:03,891This, right now, this has an index of three.
    00:09:07,312Now if we take three and we subtract one from it
    00:09:10,161we know how many dots there are in the scene,
    00:09:12,698and we're subtracting one because
    00:09:14,308we don't need to know about this null.
    00:09:16,998This null should not be counted in this equation,
    00:09:19,551and if we duplicate this,
    00:09:20,776now this becomes index four,
    00:09:22,834so you subtract one,
    00:09:23,887you know there are three dots in the scene.
    00:09:25,402So the way we can figure out the number of dots
    00:09:29,219is by looking at this layer,
    00:09:32,542so I'm gonna Pick Whip to this layer,
    00:09:34,408and I'm gonna type in .index, all right?
    00:09:37,946When you're writing expressions
    00:09:39,215you can Pick Whip to a layer
    00:09:41,140and then add a period and type in a variable name
    00:09:43,825to get information about that layer.
    00:09:46,131So I want the index of this layer, okay?
    00:09:48,969And then I wanna subtract one.
    00:09:51,085So that's the number of dots in the scene.
    00:09:54,177So right now there are two dots in the scene,
    00:09:56,684so the number of dots is gonna equal two.
    00:09:58,188So how much am I gonna have to rotate each layer?
    00:10:01,812Well, so my layer rotation is going to equal
    00:10:07,547360 degrees, which is a full circle,
    00:10:09,877divided by the number of dots.
    00:10:13,885All right, so now we have a variable called layerRot,
    00:10:16,881layer rotation,
    00:10:18,709which has a value of 180.
    00:10:20,874And if I duplicate this and now there's three dots,
    00:10:22,644this is gonna have a value of 120,
    00:10:25,417so this is always gonna be
    00:10:26,564how much each layer needs to rotate.
    00:10:29,577So now what I need to do
    00:10:31,580is figure out how many times
    00:10:33,760do I need to rotate by that amount?
    00:10:36,473What I mean is,
    00:10:37,399if there are three dots,
    00:10:39,887well then this dot needs to rotate one times this number,
    00:10:44,139and then the next dot needs to rotate two times that number.
    00:10:47,439So I basically need to find out how many dots
    00:10:50,700away from the master dot am I, okay?
    00:10:54,169And the way you can do that
    00:10:55,317is you can subtract the index of the current layer,
    00:10:59,176whatever layer you're on,
    00:11:00,369from the master index.
    00:11:02,006So if you say myIndex equals,
    00:11:08,440all right, so Pick Whip to the master,
    00:11:10,081type in .index,
    00:11:11,332and then subtract the current layer's index.
    00:11:15,285To get this layer's index,
    00:11:16,848all you have to do is type in index, okay?
    00:11:18,947So, again, myIndex is the master layer's index, three,
    00:11:23,262minus myIndex, which is two.
    00:11:26,133So this myIndex variable is actually
    00:11:27,975gonna have a value of one,
    00:11:30,231and if we multiply that number
    00:11:34,604times this layer rotation number,
    00:11:39,755we are going to get 180.
    00:11:43,012What's amazing about this little expression,
    00:11:45,112and I hope you guys understood that,
    00:11:46,577I hope that you grasped that,
    00:11:47,788type it in, break it down,
    00:11:48,705really try to understand it,
    00:11:50,344'cause here's the amazing thing:
    00:11:51,317if I duplicate this now
    00:11:52,497it's gonna automatically rotate every single layer
    00:11:56,163to make a perfect circle
    00:11:58,066no matter how many copies of this I make.
    00:12:02,429There you go.
    00:12:03,262So that's the rotation expression.
    00:12:04,566And I can see that these are,
    00:12:06,179the circles are poppin' out too far,
    00:12:08,428so I need to go into my pre-comp here,
    00:12:13,223and let's look at the Exposition,
    00:12:15,499here we go,
    00:12:16,376and I'm just gonna bring all this down a little bit.
    00:12:20,858Awesome, cool, okay?
    00:12:23,107And again, this is amazing,
    00:12:24,148I just duplicate as many times as I want,
    00:12:26,714and if I say, you know, I only want ten dots,
    00:12:28,963there you go, rotations handle automatically.
    00:12:31,234Now let's talk about this stuff,
    00:12:33,219the time offset.
    00:12:34,963So what I need to do is
    00:12:39,181I need to have a way
    00:12:40,228of setting the time that we're looking at
    00:12:43,469each of these pre-comps, right,
    00:12:44,887so the first thing you need to do is select every dot,
    00:12:47,949and enable Time Remapping,
    00:12:48,995so the hotkey is Command Option T,
    00:12:52,137or you can go up to Layer, Time, Enable Time Remapping.
    00:12:56,232So now I have a property that I can put an expression on
    00:12:59,553that will let me kind of offset these.
    00:13:01,696So let's start by making this easier.
    00:13:04,178Let's get rid of all these dots.
    00:13:06,130Okay, so here's what we want.
    00:13:08,408We want the time remap of each of our subsequent dots,
    00:13:13,861we're not gonna put an expression on the master,
    00:13:16,032remember this master is like a reference for us,
    00:13:19,432so we don't really need to have any expressions on that.
    00:13:22,794But what I wanna do is I wanna look at
    00:13:25,467whatever this time remap value is of the master,
    00:13:28,932and the good thing about a time remap property
    00:13:31,250is that it's automatically gonna go up, right,
    00:13:35,139if you don't mess with these keyframes at all
    00:13:36,888this is gonna tell you exactly
    00:13:38,764what time on this layer you're lookin' at.
    00:13:43,261So what I could do is I could have this time remap
    00:13:45,894look at this time remap and say hey,
    00:13:47,242whatever this is set to,
    00:13:49,846I want you to add whatever this time offset is.
    00:13:55,051So instead of 314 I want it to be 315,
    00:13:57,829so it'll be one frame difference.
    00:14:00,276So here's how we're gonna do that, okay,
    00:14:02,576and I'm gonna walk you through a coupla steps here.
    00:14:04,753So first we'll put an expression on here,
    00:14:07,286and actually before I do that
    00:14:08,342I wanna make sure that I open up the sliders
    00:14:12,654on my timeline so that I can Pick Whip to them.
    00:14:16,277All right, so we're lookin' at this expression,
    00:14:18,149so first thing I'm gonna do I'm gonna say
    00:14:20,177my timeOffset equals,
    00:14:24,547and I'm gonna Pick Whip to this,
    00:14:28,074and now I need to something very important.
    00:14:30,569When you are,
    00:14:32,743when you are working
    00:14:34,612in an expression in After Effects
    00:14:36,762on anything that relates to time,
    00:14:38,950you are not gonna tell this property
    00:14:42,283what frame you would like,
    00:14:43,715you have to actually tell it what second you would like.
    00:14:47,012So I don't wanna have to think in seconds up here,
    00:14:49,127I wanna say I want this delayed by two frames.
    00:14:51,582Well down here, the number two actually equals two seconds,
    00:14:56,076so if I want to convert that into frames
    00:14:58,376I need to divide by the frame rate.
    00:15:01,234So my frame rate is 24,
    00:15:02,331so I'm just gonna put divided by 24.
    00:15:05,628Okay, so I'm takin' this number, I'm dividing by 24,
    00:15:07,851so now my timeOffset is in seconds.
    00:15:11,254So then all I need to do is say well,
    00:15:14,497look at this layer, right,
    00:15:17,589so this layer's time remap,
    00:15:19,234and that is the sort of base time,
    00:15:21,536so the baseTime equals this.
    00:15:28,913And so then I need to figure out that same variable
    00:15:32,505that we figured out for rotation if you remember
    00:15:35,673we needed to figure out the difference between
    00:15:38,149the current index of this layer
    00:15:39,894and the index of the master
    00:15:41,177so we know how much to multiply that number by,
    00:15:44,216that rotation, okay?
    00:15:45,621So we're gonna do the same thing with time remap.
    00:15:46,975We're gonna say myIndex equals,
    00:15:52,591and we're looking at this layer's index
    00:15:55,153and subtracting our index.
    00:15:58,385So then what we can do
    00:15:59,688is we can say, all right,
    00:16:00,521what I wanna do is take the baseTime
    00:16:03,509and I want to add myIndex
    00:16:08,295times the time offset.
    00:16:13,206Cool.
    00:16:14,039So what this is doing in sort of English
    00:16:16,397is it's figuring out the time offset,
    00:16:18,766which right now is zero,
    00:16:19,834so let's just set the time offset to two frames.
    00:16:22,779So it's saying the time offset is two frames.
    00:16:26,755The current time we're lookin' at here,
    00:16:28,616lemme go back to the beginning here
    00:16:29,690so you can actually see it.
    00:16:30,523Now this is actually offset by two frames, cool?
    00:16:35,324So it's saying,
    00:16:36,423and you can actually see here
    00:16:37,405that now this is two frames ahead,
    00:16:40,404so actually want I wanna do is set this to negative two.
    00:16:43,271There we go, cool.
    00:16:44,554Two frames offset.
    00:16:45,477So the time offset is two frames,
    00:16:48,160the baseTime, the current time we're lookin' at,
    00:16:50,295is 19 frames.
    00:16:52,398And myIndex is three minus two, so one.
    00:16:56,439I am the first dot that comes after this master dot.
    00:17:01,063So I wanna take myIndex, which is one,
    00:17:03,739and I wanna multiply it by the offset,
    00:17:06,490so the offset's two frames.
    00:17:08,210So that's all we're gonna worry about is two frames,
    00:17:11,269and I'm gonna add that to the baseTime
    00:17:13,851to get the correct time.
    00:17:15,498And what's great is now,
    00:17:16,672if I duplicate this, right,
    00:17:20,063because we are figuring out the index of this dot,
    00:17:24,189and multiplying that times the offset,
    00:17:26,396it's gonna automatically offset
    00:17:29,286every single dot by two frames.
    00:17:32,991So this expression is not very complex, I mean,
    00:17:38,254what I find a lot with expressions is,
    00:17:40,306look at this, it's four lines,
    00:17:42,699and you could probably do it one line if you wanted to,
    00:17:45,611this just makes it a little easier to read,
    00:17:48,897it's not knowing the expressions that's hard,
    00:17:52,411it's understanding how to think like a programmer,
    00:17:55,577you know, like figuring out just
    00:17:56,720logically how to make this stuff work,
    00:17:59,546and the more that you absorb,
    00:18:02,008the better your brain's gonna get
    00:18:03,625at doing this type of stuff.
    00:18:05,631Cool, all right, and so now
    00:18:07,759we can just duplicate this as many times as we want
    00:18:10,169and you get your time offset,
    00:18:12,102and it's automatic.
    00:18:12,999And now here is one of the amazing things
    00:18:15,750about this technique
    00:18:16,719and one of the reasons that it's so powerful is, you know,
    00:18:19,700if you were gonna do this manually,
    00:18:24,117the absolute smallest amount that you could offset
    00:18:28,708one layer from another layer
    00:18:30,525is one frame.
    00:18:31,438What I mean is,
    00:18:32,271if you were just doin' this manually, like this,
    00:18:35,428you can only have one frame,
    00:18:38,572that is the minimum distance
    00:18:39,761you can move something in After Effects, right?
    00:18:42,428So if you wanted all of these things
    00:18:44,609to cascade out like this,
    00:18:46,886and there's, you know,
    00:18:48,694there's 14 dots here,
    00:18:51,812if you wanted that to take less than 14 frames,
    00:18:54,018it would be impossible.
    00:18:56,082Or you'd have to do it and then pre-comp it
    00:18:57,790and then time rehab it.
    00:18:59,108With expressions, though,
    00:19:00,899you can offset things by less than one frame.
    00:19:05,806And so now, and you can even see in real time
    00:19:08,498as I adjust this number,
    00:19:10,263it's pretty slick,
    00:19:11,307I can have this be offset by one tenth of a frame,
    00:19:16,491so you get a really tight little spiral like that.
    00:19:20,222And this is something that you honestly
    00:19:23,297are gonna have trouble doing
    00:19:24,381if you try to manually move layers around
    00:19:26,285and do it that way.
    00:19:27,920It's just not as easy.
    00:19:28,755But with this little setup it become so simple.
    00:19:31,941Cool, so now we've got the time offset part.
    00:19:35,323So now let's talk about the randomness.
    00:19:37,056So let's set the time offset to zero
    00:19:38,629so they all pop out at the same time,
    00:19:41,533and let's talk about the randomness now.
    00:19:43,057So randomness in expressions is really powerful
    00:19:48,417and it lets you create all kinds of cool behavior
    00:19:51,033where you don't even have to think about it.
    00:19:52,314So here's what we're gonna do.
    00:19:55,369We are going to hop back into our time remap expression,
    00:19:58,883and we're gonna add a little space here
    00:20:01,891and we're gonna start workin' on the random part.
    00:20:03,879And I need to make sure that I can see this slider
    00:20:07,061so that I can actually Pick Whip to it, so.
    00:20:10,274All right, so what we're gonna say
    00:20:11,532is our randomTimeAmt,
    00:20:16,853you can name these variables whatever you want,
    00:20:19,645is this, okay,
    00:20:20,478so we're grabbing that value,
    00:20:21,920and remember, we need to divide by 24
    00:20:24,299because we need this number to be in seconds, okay?
    00:20:28,943Okay, so now if we think about this,
    00:20:31,959if we set this to two frames,
    00:20:34,740what, to me, what I really want is,
    00:20:36,683I want that to randomly change this time remap,
    00:20:42,740either or backwards two frames.
    00:20:45,023I wanna have it go both ways, okay?
    00:20:48,078Now, here's how you do randomness in After Effects.
    00:20:50,793It's actually pretty easy.
    00:20:51,879So why don't we say the randomActual, okay,
    00:20:56,951so this is gonna be the actual random amount
    00:21:00,392that we're gonna choose here is going to be,
    00:21:03,463and here's how it works, okay,
    00:21:04,678and if you forget this you can always click this arrow,
    00:21:07,322and look in this little popup box,
    00:21:09,636so here's the random numbers group,
    00:21:11,575and you can see all the different expression commands
    00:21:14,678that deal with randomness.
    00:21:16,414And random is the easiest one.
    00:21:18,375So all you do is you type in random,
    00:21:21,649and then you put the minimum and the maximum number
    00:21:24,049that you would like random to give you.
    00:21:26,399So I'm gonna say random, and then in parentheses,
    00:21:29,223so the minimum number I want
    00:21:31,180is the negative randomTimeAmt,
    00:21:35,863and the maximum value I want is randomTimeAmt.
    00:21:40,827Okay, so, this random command is actually going to give me
    00:21:45,130a number somewhere between,
    00:21:48,025if this is set to two,
    00:21:49,288let me actually set it to two,
    00:21:51,055randomActual is going to be a number
    00:21:53,130somewhere between negative two and two.
    00:21:55,790So then all I have to do is take that number
    00:22:00,273and add it to this expression here,
    00:22:04,430and now I will get
    00:22:06,854my time offset will be sorta taken care of,
    00:22:09,229but then if I have any randomness,
    00:22:10,891that will also be taken care of.
    00:22:13,130So lemme crank this number up, all right,
    00:22:17,657and you can see that now this,
    00:22:19,777and actually lemme just go ahead
    00:22:21,036and delete all of these really fast,
    00:22:23,716just go back down to two dots.
    00:22:25,333So look at the time remap here
    00:22:26,508and you're gonna see somethin' funny.
    00:22:28,323All right, you see how the animation's all messed up now?
    00:22:30,795And if you look at the time remap,
    00:22:32,955at the actual value,
    00:22:33,792if I go frame-by-frame through it,
    00:22:35,030you see it jumps around, right?
    00:22:38,097So when you use random numbers in an expression
    00:22:41,092there's one extra step you have to do.
    00:22:43,654And that is, you have to seed, it's called seeding,
    00:22:46,908you have to seed the random number.
    00:22:49,717So for example, if you have 10 layers,
    00:22:53,003and each of them is gonna have
    00:22:54,357this exact same random expression on there,
    00:22:57,678how are you supposed to ensure
    00:22:59,594that the random number for layer two
    00:23:01,623is different from the random number for layer three?
    00:23:04,888And the way it works is you have to give
    00:23:07,050the random expression something
    00:23:09,920to base the random number off of
    00:23:11,732that is unique to each layer, okay.
    00:23:15,179And so what I'm gonna do, and the command for this,
    00:23:17,479if you ever forget it,
    00:23:18,858come in here, Random Numbers, Seed Random,
    00:23:21,007this is what you're gonna do.
    00:23:22,162And there's two properties, okay?
    00:23:24,991So the first one is the seed,
    00:23:27,062so here's what we're gonna do,
    00:23:28,975we'll change the word seed to index.
    00:23:32,093When you're seeding the random number
    00:23:34,223you want something that is unique to every instance
    00:23:38,977of this random number, right,
    00:23:40,558and so each layer has a different index.
    00:23:43,367This is index two, the next one will be index three,
    00:23:46,311and then four and then five,
    00:23:47,900so that's gonna ensure that this random command
    00:23:51,138gives us a different number for each layer.
    00:23:53,041Now this is very important:
    00:23:54,459timeless equals false.
    00:23:55,806By default the random number will change
    00:23:59,075on every single frame.
    00:24:00,917You don't want that.
    00:24:01,750If you type in true, that sets
    00:24:03,570the timeless variable to true,
    00:24:05,745meaning it picks one number and it sticks with that number.
    00:24:09,269So now, there you go.
    00:24:12,174Now this is offset by somewhere
    00:24:14,359between negative 10 and 10 frames.
    00:24:16,456So now if I duplicate this a whole buncha times,
    00:24:20,471and we play it, there you go: randomness.
    00:24:26,029Pretty awesome!
    00:24:27,572And so lemme scrub forward here.
    00:24:30,792Now here's one of the problems that you're gonna run into.
    00:24:33,324Because I have this set to 10 frames,
    00:24:36,898that means that some of these are gonna actually
    00:24:39,314be set 10 frames before the master,
    00:24:42,857and so even on frame zero
    00:24:44,246you're already gonna see some of this animation.
    00:24:46,672So you could mess with the expressions to fix that.
    00:24:48,933I found it easier to just jump into your pre-comp
    00:24:51,800and just knock this thing forward 10 frames.
    00:24:54,718And the way I did that, if you don't know the hot key,
    00:24:56,219you select the layer,
    00:24:57,052you hold Shift Option,
    00:24:59,508Shift Option, Page Up or Page Down,
    00:25:04,019it will nudge your layer forward or backwards 10 frames.
    00:25:07,508So now there you go.
    00:25:10,249Now you've got complete randomness happening.
    00:25:13,562But if you only wanted a little bit of randomness
    00:25:17,562but you still wanted these to happen sort of in order,
    00:25:23,497you can do it like that.
    00:25:24,901And so now you can actually control
    00:25:26,985both the sort of linear time offset
    00:25:29,128and also the random time offset.
    00:25:32,486And if you wanna stop watching right now
    00:25:35,291that's the whole trick right there.
    00:25:37,056The beauty of this is that I can take
    00:25:39,946this Dot_MOGRAPH and put that in its own comp,
    00:25:43,165and I could put a fill effect on there,
    00:25:47,079and I actually used some of the tricks
    00:25:48,917that I've used in other tutorials
    00:25:50,929to get a nice little 3D look on that,
    00:25:53,397and pick some nice colors for it,
    00:25:55,394and so now I've got this.
    00:25:57,144And what I can do,
    00:25:57,977lemme call this FinalCOMP2,
    00:26:02,175so if I duplicate Dot_MOGRAPH
    00:26:04,106and I call this, I don't know,
    00:26:06,589I'll show you how I did the cool circle,
    00:26:08,040so this would be Circle_MOGRAPH, okay.
    00:26:11,802And what I wanna do
    00:26:14,420is take this dot,
    00:26:17,531this little animation we made,
    00:26:19,820and I'm gonna duplicate it and I'm gonna call it Circle.
    00:26:23,504And let's go in here,
    00:26:24,337and what I wanna do is,
    00:26:26,508lemme duplicate this dot,
    00:26:28,638and go to the beginning here,
    00:26:29,471delete all these keyframes
    00:26:30,594and scale it up to 100,
    00:26:33,162and then I'm gonna change the Ellipse path to be pretty big.
    00:26:38,162And I'm gonna get rid of the fill
    00:26:41,043and I'm gonna turn the stroke up a little bit,
    00:26:43,376and what I wanna do is make sure that this circle goes
    00:26:47,424outside of where this little dot is landing,
    00:26:49,922so I'm gonna crank this up a little bit like that,
    00:26:53,151and now I'm gonna delete the dot.
    00:26:56,017And then I can add a little trim paths here, right,
    00:27:00,631and now I can just get like a little sweep like this.
    00:27:03,807An so what I could do is I could animate maybe
    00:27:06,890the Ellipse path size
    00:27:08,679and I could also animate the offset of this,
    00:27:12,390and maybe the ending too,
    00:27:13,793so let's go forward 20 frames,
    00:27:17,230and let's put keyframes
    00:27:18,063on all those things we wanna keyframe, all right ,
    00:27:20,987and then we'll go back to the beginning
    00:27:22,838and we'll animate the offset so it kinda moves around,
    00:27:26,279and we'll animate the end,
    00:27:29,664and why don't we also animate the start, too,
    00:27:38,530right, so we can have it sort of start
    00:27:44,123and kind of animate around
    00:27:45,701and I'm gonna offset this a little bit,
    00:27:50,323so you get kind of this, let's see,
    00:27:55,001I don't really like what this is doin' yet,
    00:27:57,445cool, so you've got this interesting little guy,
    00:28:00,461and it's gonna end with a nice big chunk of a circle,
    00:28:05,641there we go, cool.
    00:28:07,781Sorry that took so long,
    00:28:08,939I'm really anal when it comes to this kinda stuff.
    00:28:12,300And then on top of that
    00:28:13,902why don't we also animate the size?
    00:28:16,806So it'll start out much smaller
    00:28:20,584and maybe really crank up like that.
    00:28:25,066I'm gonna really crank these bezier handles too.
    00:28:27,681Cool, so you get something kinda interesting like that.
    00:28:31,907Now what happens if you go into this Circle_MOGRAPH,
    00:28:36,979select all these layers,
    00:28:38,764and then you can just hold Option
    00:28:40,426and just replace all of those with your circle.
    00:28:43,522And then you can just duplicate the layers
    00:28:46,271until you have enough to make the complete circle.
    00:28:48,648If you didn't have enough in there
    00:28:50,219you just duplicate,
    00:28:51,052duplicate, duplicate, duplicate, duplicate.
    00:28:53,353And there you go, now I have enough,
    00:28:54,333and now I can go up to my control
    00:28:56,331and say all right,
    00:28:57,740I want nothing on the time offset,
    00:28:59,895but I want a random offset of maybe eight frames.
    00:29:03,467And if we go to the first frame,
    00:29:04,828you'll see that you're still seeing some of the animation,
    00:29:06,890so I need to go into my pre-comp and nudge this forward
    00:29:11,479eight frames,
    00:29:12,868and now you get this.
    00:29:15,937Cool, right?
    00:29:16,850And it's like, crazy looking!
    00:29:20,118And it took no time at all to make.
    00:29:21,524And I want it to happen faster,
    00:29:23,519it's too slow, so I'm gonna
    00:29:25,750get these closer together, there we go.
    00:29:28,894Right?
    00:29:29,727And then you just come to your final comp
    00:29:32,858or Final_FOMP2 and you drag your Circle_MOGRAPH in there,
    00:29:37,593and then you put a fill effect on there
    00:29:39,474and you make it whatever color you want
    00:29:42,121and what I did, also,
    00:29:43,800is I would duplicate this and offset it
    00:29:45,962and scale it down and, you know,
    00:29:47,905just sort of start making repeating patterns,
    00:29:51,027and what's cool is now you have this system in place
    00:29:55,762where anything you make,
    00:29:58,576you can just replace these layers
    00:30:02,154and all the expressions will transfer over
    00:30:05,322and you're done.
    00:30:06,234And you can control all kinds of stuff,
    00:30:09,319so if we look at some of the things I did, right,
    00:30:11,686I created this animation, right,
    00:30:14,157this triangle animates on,
    00:30:16,917that's all it does.
    00:30:17,900Just animates on and points that way.
    00:30:19,840And so then if we go here,
    00:30:22,756you can see that I have a random offset on them
    00:30:26,828so they all end up doing that,
    00:30:28,354and then in this comp I also added a scale,
    00:30:31,328I keyframed the scale of them,
    00:30:32,929so that when they came up,
    00:30:35,182lemme make this a little bit bigger,
    00:30:37,238when they animate on
    00:30:39,425they then shrink down.
    00:30:41,753So that was like a little extra layer of animation to it,
    00:30:44,033but I also did things like these little lines, right?
    00:30:46,878If we look at these, these are very simple.
    00:30:48,709I animated one line, just doin' that,
    00:30:52,083and I put it in my little Mograph setup and I did this.
    00:30:55,566And in this case, this is one of those things where
    00:30:57,857the offset not very much, you know.
    00:31:00,655The offset here is half a frame, right?
    00:31:05,273A half a frame!
    00:31:07,308You can't do that in After Effects very easily,
    00:31:10,460but if you set up the expressions,
    00:31:11,620you can offset stuff by half a frame
    00:31:13,153and get this really tight little spiral.
    00:31:15,409So anyway, what I hope you guys take away from this
    00:31:20,370aside from expressions are geeky,
    00:31:23,971is that yes, expressions are geeky,
    00:31:26,718but if you can just wrap your head around it a little bit,
    00:31:29,254and at the very least, if you just know what's possible,
    00:31:32,399and you know that you can go to schoolofmotion.com
    00:31:34,367and copy and paste these expressions whenever you need to,
    00:31:37,375just maybe buy me a beer if you ever meet me,
    00:31:40,732you can do some super powerful crazy intricate stuff
    00:31:43,852in After Effects without a ton of effort.
    00:31:46,492You know, this whole demo here I probably put together
    00:31:49,233in about 45 minutes because
    00:31:50,733once you have the expressions set up,
    00:31:53,307you can just keep makin' stuff,
    00:31:54,851and just keep offsetting it and you know,
    00:31:58,905there are much better designers out there than me
    00:32:00,862that can probably do something amazing with this.
    00:32:03,428So I hope you guys dug this,
    00:32:05,708I hope, you know,
    00:32:06,728this is just scratching the surface of what you can do,
    00:32:09,298you really could do a whole bunch more really cool
    00:32:11,866MoGraph-style stuff with expressions,
    00:32:13,930but this is hopefully a good little intro for everybody.
    00:32:17,183So thank you very much,
    00:32:18,197these expressions will be available
    00:32:19,530for copy/paste on the site,
    00:32:21,338and I will see you next time.
    00:32:24,095Thank you so much for watching.
    00:32:25,434I hope this was interesting
    00:32:26,818and I hope you learned something new
    00:32:28,307about how to use expressions in After Effects,
    00:32:31,035and just how powerful they can be.
    00:32:32,972If you have any questions or thoughts about this lesson,
    00:32:35,593definitely let us know,
    00:32:36,964and we'd love to hear from you
    00:32:38,428if you use this technique on a project,
    00:32:40,317so give us a shout on Twitter @schoolofmotion
    00:32:42,947and show us your work.
    00:32:44,674Thank you again, and I'll see you on Day 29.
    00:32:51,178(high-energy electronic music)