ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# function curve drives interpolation

FAQ   •   VIEW ALL function curve drives interpolation on Feb 25, 2013 at 9:32:00 pm

Hello all. I am wondering if it is possible to use a function curve keyed on another parameter to act as a replacement of "linear" or "ease" interpolation expression? I searched around here and found only one relevant atempt to make this work. Is it even possible, given the AE scripting language?

Cheers

AK Re: function curve drives interpolationon Feb 25, 2013 at 11:08:38 pm

Interesting question...

Suppose you set up a template null and you keyframe the rotation property going from 0 to 1 degree as the time goes from 0 to 1 second. Use that keyframed segment to set up the ease curve you want.

Then on another layer you could use linear keyframes and apply an expression like this to generate a similar curve:

``` template = thisComp.layer("template").transform.rotation; n = 0; if (numKeys > 0){ n = nearestKey(time).index; if (key(n).time > time) n--; } if (n == 0 || n == numKeys){ value }else{ v1 = key(n).value; v2 = key(n+1).value; t1 = key(n).time; t2 = key(n+1).time; v1 + (v2-v1)*template.valueAtTime((time-t1)/(t2-t1)); } ```

I hope that helps.

Dan Re: function curve drives interpolationon Feb 26, 2013 at 4:32:07 pm

Hello Dan. Apologies, I believe I didn't phrase this question well enough. Save I am setting an expression on scale like so (see below)

so that the layer's width scales between 100% and 10% depending on its position between the two shape layers in the expression below. "Linear" will of course yield a linear result. If the layer was half way between the 2 layers it's width would be 50%, 3/4 of the way there 75%, etc etc.

But is there a way to replace "linear" with a curve with multiple key frames between 0 and 1, so you could kind of art direct the range of scale values as the layer travels between the two points....

Cheers

AK

```a = linear(transform.position, thisComp.layer("Shape Layer 1").transform.position, thisComp.layer("Shape Layer 2").transform.position, 100, 10); b = transform.position; [a,b] ``` Re: function curve drives interpolationon Feb 26, 2013 at 9:32:41 pm

I'm not sure if this is what you're looking for, but if you wanted to scale a layer from 10% to 100% as its x postion moves between the x positions of Shape Layer 1 and Shape Layer 2, and you wanted to apply a cubic ease-in to the scaling, you could do it like this:

``` function myEase(t){ return t*t*t; // cubic ease in } minVal = [10,10]; maxVal = [100,100]; x1 = thisComp.layer("Shape Layer 1").transform.position; x2 = thisComp.layer("Shape Layer 2").transform.position; x = transform.position; myT = linear(x,x1,x2,0,1); linear(myEase(myT),minVal,maxVal) ```

To apply a different ease, you would just need to change the function. The key to the function is that it expects values between 0 and 1, and returns values between 0 and 1.

Dan Re: function curve drives interpolationon Feb 26, 2013 at 9:39:53 pm

Thanks Dan. These are two great lessons / exercises in and of themselves.
I'm going to try to actually combine these two things into what I think I'm trying to achieve. I will post back my results.

Cheers

AK Re: function curve drives interpolationon Jun 24, 2015 at 1:37:08 am