Skip to main content
S_ A
Inspiring
Aug 29, 2025 7:15 PM UTC
Answered

how to write expression in such case -15 (trim path looping randomly)

Hi,

 

I want to loop the start and end of trim path but randomly for each line.. like line 1 start it's loop at 2 second, line 3 at 4 second. and none of them will overlap with one another's animation timing, I mean suddenly line 2 start its loop and line 3 and line 1 are not looping, again when line 1 looping line 2 and 3 not animating. . they will happen solo at their own time. And I want this to continue for as long as the main comp goining on, say 20 second, each line will be in a loop but different timing... . How can I write the expression? Thank you.

 

Dan Ebberts
Dan EbbertsCorrect answer
Community Expert
Aug 29, 2025 9:39 PM UTC

Here's an example. It's probably not exactly what you're after, but it might be close enough to get you started. Add a null, name it "Controls" and add a Point Control named "Line and Percent". Add this expression to the Point Control:

minLine = 1; // minimum line number participating
maxLine = 3;  // maximum line number participating
runDur = 1; // duration of animation time

seed = Math.floor((time-inPoint)/runDur);
seedRandom(seed,true);
curLine = Math.floor(random(minLine,maxLine + 1));
curPct = (((time-inPoint)%runDur)/runDur)*100;
[curLine,curPct]

For each of the line shape layers (named in the format "Line n") add this expression for the Trim Path's Start parameter:

ctrl = thisComp.layer("Controls").effect("Line and Percent")("Point");
curLine = parseInt(ctrl.value[0],10);
curPct = ctrl.value[1];
if (curLine == index){
  ease(curPct,20,100,0,100)
}else
0

and this for the End parameter:

ctrl = thisComp.layer("Controls").effect("Line and Percent")("Point");
curLine = parseInt(ctrl.value[0],10);
curPct = ctrl.value[1];
if (curLine == index){
  ease(curPct,0,30,0,100)
}else
0

You may need to fiddle with the numbers.

3 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
Aug 29, 2025 9:39 PM UTC

Here's an example. It's probably not exactly what you're after, but it might be close enough to get you started. Add a null, name it "Controls" and add a Point Control named "Line and Percent". Add this expression to the Point Control:

minLine = 1; // minimum line number participating
maxLine = 3;  // maximum line number participating
runDur = 1; // duration of animation time

seed = Math.floor((time-inPoint)/runDur);
seedRandom(seed,true);
curLine = Math.floor(random(minLine,maxLine + 1));
curPct = (((time-inPoint)%runDur)/runDur)*100;
[curLine,curPct]

For each of the line shape layers (named in the format "Line n") add this expression for the Trim Path's Start parameter:

ctrl = thisComp.layer("Controls").effect("Line and Percent")("Point");
curLine = parseInt(ctrl.value[0],10);
curPct = ctrl.value[1];
if (curLine == index){
  ease(curPct,20,100,0,100)
}else
0

and this for the End parameter:

ctrl = thisComp.layer("Controls").effect("Line and Percent")("Point");
curLine = parseInt(ctrl.value[0],10);
curPct = ctrl.value[1];
if (curLine == index){
  ease(curPct,0,30,0,100)
}else
0

You may need to fiddle with the numbers.

Translate
S_ A
S_ AAuthor
Inspiring
Aug 30, 2025 11:32 AM UTC

Thank you so much. I needed this guidance. Thank you.

Translate