ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Creating a Shape Path Tween

FAQ   •   VIEW ALL
 Creating a Shape Path Tween on Mar 12, 2020 at 11:15:49 am

Hi Guys,

It's been a long time since I posted here!

Imagine I had two shape paths with the same number of points.

Is it possible, using the path property expressions, to create a third shape which is always a halfway morph between shape one and shape two?

I have tried using keyframes and the .path.valueAtTime property, but the in-between path always "catches up" with the second shape, whereas I want it to remain a 50% tween between shape one and shape two, no matter how I alter shape two.

Here's a frame of what I want to acheive:

Shape one is the straight "F". Shape two is the outer shape. Shape three should remain 50% between shape one and shape two even if I alter shape two over time.

I hope this makes sense!
Thank you,

Jason Guest

 Re: Creating a Shape Path Tweenon Mar 12, 2020 at 3:44:11 pm

You can do it with a linear interpolation. you can change linear to ease if you want below, or try to implement penner easing with some more complex functions.

If you wanted to use keyframes instead of different paths, you would generate two different times (ta, tb) using key(1).time, key(2).time, and then instead generate Pa/Ta/Oa using ta instead of t, and the same thing for B sets.

You miiiight be able to try:

``` P = linear(m,0,1,Pa,Pb); T = linear(m,0,1,Ta,Tb); O = linear(m,0,1,Oa,Ob); ```

but I am unsure if it will work, not at a workstation to test if linear can handle longer arrays.

```A = thisComp.layer("path A").content("group 1").content("Path 1").path; //path A point B = thisComp.layer("path B").content("group 1").content("Path 1").path; //path B point; m = .5 // percent to morph between them t = time; //sets the time to grab Pa = A.points(t); //points for path A Ta = A.inTangents(t); inTangents for path A Oa = A.outTangents(t); outTangents for path A Pb = B.points(t); Tb = B.inTangents(t); Ob = B.outTangents(t); P = []; //final points T = []; //final inTangents O = []; //final outTangents for(i=0; i<Pa.length; i++){ //linearizes all properties for each point P.push(linear(m,0,1,Pa[i],Pb[i])); T.push(linear(m,0,1,Ta[i],Tb[i])); O.push(linear(m,0,1,Oa[i],Ob[i])); } createPath(P,T,O,A.isClosed()); //creates new path, checks if A was closed```

Alex Printz
Mograph Designer

 Re: Creating a Shape Path Tweenon Mar 12, 2020 at 4:35:19 pm

I think this will work:

``` p1 = content("Shape 1").content("Path 1").path; p2 = content("Shape 2").content("Path 1").path; v1 = p1.points(); v2 = p2.points(); tIn1 = p1.inTangents(); tIn2 = p2.inTangents(); tOut1 = p1.outTangents(); tOut2 = p2.outTangents(); v = []; tIn = []; tOut = []; for (i = 0; i < v1.length; i++){ v[i] = (v1[i]+v2[i])/2; tIn[i] = (tIn1[i]+tIn2[i])/2; tOut[i] = (tOut1[i]+tOut2[i])/2; } createPath(v,tIn,tOut,p1.isClosed()) ```

Dan

 Re: Creating a Shape Path Tweenon Mar 12, 2020 at 5:18:30 pm

Amazing! Thanks very much guys, this is one I definitely wouldn't have figured out by myself.

Alex, I tried yours first and it worked straight out of the box. I'll have a play with yours too, Dan and hopefully I'll be able to make sense of how they both work!

I really appreciate your efforts, thank you.

Jason