• | **Driving a path's shape using a slider control.**
on Jul 26, 2017 at 6:22:02 am |

Hello!

I am attempting to animate a X/Y graph whose shape is dependent upon a variable (it's a correlation coefficient) that I have hooked up to a slider control.

The shape of the graph begins perfectly linear and upward sloping when the correlation is 1.00, but becomes increasingly convex toward the x-axis (or toward the left) as I decrease the slider control variable (the correlation) from 1.00 toward 0.00.

Right now I have been able to achieve this by:

Having a solid object whose position moves over a period of 50 frames according to the expression for a fixed value of the slider (correlation = 1.00)

Converting the expression to 50 keyframes

Pasting the 50 position keyframes as values onto a Shape Layer's path (and adding a stroke)

Deleting the 50 position keyframes on the solid, changing my slider control from 1.00 to say 0.75, converting the expression to new 50 new keyframes, then pasting them on another path on my shape layer

Rinse repeat for other values of my slider control (say 0.50, 0.20 and finally 0.00)

Then creating a final path that I animate/morph from one path shape (based on the original value of 1.00) to the other path shapes of 0.75, 0.50, 0.20, and finally 0.00

The obvious problem here is that for each intermediate shape of the curve that I was to display, I have to convert the expression to keyframes and paste it into a new path on my shape layer.

My question is whether it's possible to have my shape graphed once and linked to my slider control and then have the shape change and become more convex as I animate the slider control from 1.00 toward 0.00.

I've been able to simulate what I'm after using a write-on effect attached to the position of the solid I was using to generate the keyframes (& toWorld, of course), but can you bend a path on a shape layer directly using an expression linked to a slider?

Thanks in advance for any help ☺

- Pete

• | **Re: Driving a path's shape using a slider control.** on Jul 26, 2017 at 4:03:41 pm |

I can't completely picture what you're trying to do, but it seems like you could have a shape with two keyframes for the start (straight) and end (curved) configurations over a fixed period, then use valueAtTime() to get the correct tween shape.

Dan

• | **Re: Driving a path's shape using a slider control.** on Jul 26, 2017 at 4:36:27 pm |

Thanks for your response, Dan.

I guess I didn't trust A.E. to give me the correct/precise curve I'm after at any of the intermediate values between the start and the end when using valueAtTime().

I'll test the tweens now against the precise curves that I've calculated and see how close they are.

Cheers again!

• | **Re: Driving a path's shape using a slider control.** on Jul 26, 2017 at 5:31:56 pm |

Here's what I get.

Red lines are the precise curves that I

*should* get at each pause.

Green line is the tweened curve (based only off the start and end red lines), paused when it should actually trace the red curve next to it. Not quite accurate enough!

• | **Re: Driving a path's shape using a slider control.** on Oct 19, 2017 at 10:40:55 pm |

For anyone who comes across this post in the future, the question has now been thankfully made redundant by the new createPath ability in After Effects CC 2018. Thank you Adobe! ☺ This feature is going to be extremely useful going forward!

You can define an array of arrays (points) directly in an expression now for your path. It will be an array of [x,y] arrays (like the default values that the function throws in when you select it from the expression menu).

**Dan, if you read this**, is there a neater way of creating an array of arrays (rather than making them separately and then stitching them together below like I have)? What I've done works perfectly, but I'm sure there's a cleaner way where you'd define it in terms of both i & j in one single step.

---------

total = 200; // "total" is the number of points you want to define along a mathematical curve

// inputs to feed into my curve as an example (x axis variable = standard deviation, y axis variable = return)

ret2 = 15; // low risk asset's return

ret1 = 30; // high risk asset's return

sd2 = 25; // low risk asset's volatility

sd1 = 30; // high risk asset's volatility

corr=thisComp.layer("Control Null").effect("Correlation")("Slider")/100; // the correlation coefficient variable I want to animate the change in the curve's shape for

// calculation of an array of my x variables for all "total" points along the curve

var x = Array(total);

x[0]= 1 * (0*sd1 + 1*sd2);

x[x.length - 1] = 1 * (1*sd1 + 0*sd2);

for (i = 1; i < (x.length - 1); i++) {

x[i] = 1 * Math.sqrt(((Math.pow(((i -1)/(x.length - 1)),2) * Math.pow(sd1,2)) + (Math.pow((1 - ((i -1)/(x.length - 1))),2) * Math.pow(sd2,2))) + (2 * ((i -1)/(x.length - 1)) * (1 - ((i -1)/(x.length - 1))) * sd1 * sd2 * corr)); // this is the main equation i was wanting to change/animate in my original post

}

// calculation of an array of my y variables for all "total" points along the curve

var y = Array(total);

y[0]=-1 * (0*ret1 + 1*ret2);

y[y.length - 1] = -1 * (1*ret1 + 0*ret2);

for (i = 1; i < (y.length - 1); i++) {

y[i] = -1 * ((((i -1)/(y.length - 1)) * ret1) + ((1 - ((i -1)/(y.length - 1))) * ret2)); // this bit is just a weighted average

}

// stitching the two arrays together to a single array "a" of [x,y] position points for my path to follow.

var a = Array(total);

for (i = 0; i < a.length; i++) {

a[i] = [x[i] , y[i]];

}

// creating the open path whose points follow the curve define by the array of arrays "a"

createPath(points = a, inTangents = [], outTangents = [], is_closed = false)

• | **Re: Driving a path's shape using a slider control.** on Oct 19, 2017 at 11:24:14 pm |

I think you could just do something like this:

a = [];

and then have one big loop where you calculate both x and y, and populate the array:

for(.... ){

x = //something;

y = //something;

a.push([x,y]);

}

Dan