The linear method is, hands down, my favorite expression.
You'll find it extremely useful when combined with expression Slider Controls.
If you've ever used a Cinema 4D Range Mapper, you'll love this expression.
The linear method is a tool for converting value ranges.
It starts with the word linear, and includes three to five arguments, wrapped in parenthesis
and separated by commas.
The first argument is always a custom input source, which can be time,
value, or another property reference.
The basic method uses three arguments, with the second and third arguments representing
the output min and max values as the input value changes from 0 to 1.
The long-form version is more flexible, and it accepts five arguments.
The second and third arguments become input min and max, while the output min and max
are moved to the fourth and fifth arguments.
Let's say you wanted to pair the Rocket's animation to a Rocket Launch Slider Control.
By using a linear method, you can map the expression Slider Control
to the Rocket's Y Position value.
In this example, you'll notice a Controller layer which contains an expression
Slider Control named Rocket Launch.
If you open the Position property on the Rocket layer, we can use the pick whip to select
the Rocket Launch Slider Control.
So, because we're only going to work with the Y axis, I'm gonna right-click Position,
and separate the dimensions so we can get all three here.
Then, add a new expression to the Y Position property, and then highlight the control
so that we can see the Rocket Launch Slider Control.
Now, come down and grab the pick whip and drag it up to the Rocket Launch Slider,
and let go, and it's gonna give us the reference to the Slider right here as automatic syntax.
This reference is gonna serve as our linear function's input.
So, at the very beginning of this comp, I'm gonna start the linear method by typing linear,
open parenthesis, and then coming to the very end of the Slider at the end of the reference,
and adding a comma.
So this is our first argument.
For the second argument, which is the Slider's minimum value, I'm gonna type 0, comma,
and then the max value, I'm gonna just use 100, comma.
You'll also need to specify the output min and max.
So, immediately after 100, you're gonna create a fourth argument, which is gonna be value,
to reference the original value of the Y Position, followed by another comma.
And then the fifth argument is gonna be value, followed by a subtraction operator,
and I'm gonna use a value of 1500 for this, so we're gonna subtract 1500
from the Rocket's Position as the Slider goes from 0 to 100.
And then finally, at the very end you'll wanna close the parenthesis.
And if you click off the expression field, you'll notice that nothing's changed
because your value is still set to 0 on the Rocket Launch.
But if you change this to 50, which is halfway between our min and max, and hit Enter, you'll
notice the Rocket has now moved up in the sky.
And then, if you change this to 100, it will complete its animation.
You can also slide the Rocket Launch slider, and it's gonna animate
between the min and max values that you specified.
The coolest part about this is, because we're using the value as a relative reference,
you can actually select the Rocket layer and move it anywhere in your composition.
I'm gonna put it right here behind this mountain.
And, if you come back up to the Control, and now if you slide the Slider value from 0 to 100,
the Rocket still animates 1500 pixels on its Y axis because it's using value
as its starting position instead of a hard-coded value.
Now, let's look at a couple variations of the interpolation method.
These methods can be used interchangeably with linear to change how a value is remapped.
All you have to do is replace linear with these method names.
The first one we are gonna look at is the ease method and it's gonna add a standard
ease in and ease out at the beginning and end of the value range.
It behaves just like the Easy Ease keyframe function in After Effects.
And so if you come in and change linear to ease, and click out of the expression.
And then if you come up to the Control layer, set a keyframe at 0, come forward in the composition
and set a keyframe to 100, you can then look at the Post-Expression Graph
to see how this value's changing.
Now, even though we have linear keyframes on this, we didn't actually apply Easy Ease
to the Control layer, we're still getting a nice ease and that's because of the expression.
If I was to come in here and change this back to linear, like we had before, and click away,
now the value change is linear and it no longer has the ease curve.
Two other variations of this are easeIn and easeOut, and they are identical to the
ease method, except they only provide ease interpolation at either the beginning
or the end of the output range.
So, if you come over here to the ease function and simply add In, with a capital I,
and click on the Post-Expression Graph, and open the Graph Editor, you'll see exactly
what this value is doing.
It has a nice ease in at the beginning, and switches to a linear at the end.
And if I select Y Position and change this to Out, capital O, and click away from the expression,
it just switches how the ease is interpolated.
So now, the linear keyframe is at the beginning, and it eases out at the end of the value range.
You can find the linear and ease syntax in the Expression Language Menu under Interpolation.
We've arrived at the end of Lesson 205: Remapping Values with the Linear and Ease Methods.
If you enjoy this expressions course, consider purchasing the paid content.
It includes in-depth documentation, extra tutorial content, high definition videos,
and all the project files used in the training.
Your purchase will help to create more free courses like this in the future.