Skip to main content
Participant
July 6, 2025
Answered

Animate lines of various lengths at same speed so smaller lines finish first

  • July 6, 2025
  • 1 reply
  • 327 views

Okay, first time doing a post like this, so please go easy on me everyone. I have been banging my head against this roadblock for the last few days

 

I have multiple lines that need to have a trim effect that comes out from the edge of the screen. They are all of various lengths and angles. What I am after is a way that all the lines emerge at the same speed, so that the shorter ones finish first while the longer ones finish last. Trim path seems to be the way to go, but that only works on a percentage, and I haven't found another way to get this to work. I figure an expression might be the way to go, but nothing I have tried has worked 

Correct answer Dan Ebberts

I think to do it, your expression has to calculate the length of the path. This is an iterative expression for the Trim Path's End property that will give you the approximate length, which you can then use to calculate the current End percent:

spd = 100; // trim speed (pixels per second)
path = content("Shape 1").content("Path 1").path
numPts = 100;
accum = 0;
p1 = path.pointOnPath(0);
for (i = 1; i <= numPts; i++){
  p0 = p1;
  p1 = path.pointOnPath(i/numPts);
  accum += length(p0,p1);
}
(spd*(time-inPoint)/accum)*100

 

1 reply

ShiveringCactus
Community Expert
Community Expert
July 7, 2025

I'd be really tempted to not use Trim paths for this and use the linear wipe instead.  Or use a mask or track matte for the layer to do the same thing. 

But you may have more things going on on your shapes.  

You could have a trim paths in each shape group, so that you have multiple keyframes to deal with.

 

Participant
July 8, 2025

If the lines were all going in the same direction, that would have been an option for me, but I have lines on all sides of different angles and lengths between points, and go towards the center. 

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
July 8, 2025

I think to do it, your expression has to calculate the length of the path. This is an iterative expression for the Trim Path's End property that will give you the approximate length, which you can then use to calculate the current End percent:

spd = 100; // trim speed (pixels per second)
path = content("Shape 1").content("Path 1").path
numPts = 100;
accum = 0;
p1 = path.pointOnPath(0);
for (i = 1; i <= numPts; i++){
  p0 = p1;
  p1 = path.pointOnPath(i/numPts);
  accum += length(p0,p1);
}
(spd*(time-inPoint)/accum)*100