# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Expression to loop a layer property which has expression on it.

• # Expression to loop a layer property which has expression on it.

• Hi guys, I have a layer which basically animates from one point to other point on x-axis which has a custom speed values and duration of 2 secs. Currently I am achieving this by below expression function

function customBezier(t,tMin,tMax,value1,value2,bezierPoints){if(arguments.length!==6)return value;var a=value2-value1;var b=tMax-tMin;var c=clamp((t-tMin)/b,0,1);if(!(bezierPoints instanceof Array)||bezierPoints.length!==4)bezierPoints=[0,0,1,1];return a*h(c,bezierPoints)+value1;function h(f,g){var x=3*g;var j=3*(g-g)-x;var k=1-x-j;var l=3*g;var m=3*(g-g)-l;var n=1-l-m;var d=f;for(var i=0;i<5;i++){var z=d*(x+d*(j+d*k))-f;if(Math.abs(z)<1e-3)break;d-=z/(x+d*(2*j+3*k*d));}return d*(l+d*(m+d*n));}}

t = time;

dur = 2;

startVal = 200;

endVal = 800;

customBezier(t,0,dur,startVal,endVal,[0.76, 0, 0.24, 1]);

Is there anyway that I could loop this animation just like using pingpong expression on two keyframes.

Thank You

• Try replacing everything after the function with this:

`dur = 2;n = Math.floor(time/dur);t = n%2 ? dur - time%dur : time%dur;startVal = 200;endVal = 800;customBezier(t,0,dur,startVal,endVal,[0.76, 0, 0.24, 1]);`
• It works…Thank you Dan. Is it possible to explain what does t = n%2 ? dur – time%dur : time%dur; does here

• n is the count of how many 2-second periods there have been. n%2 tells you whether n is odd or even. For the odd-numbered periods, you want t to go backwards (by subtracting time%dur from dur) otherwise, go forwards (just time%dur). time%dur gives you the remainder of of the time/dur operation, and is what generates the looping.

• Thanks Dan for explaining.

Viewing 1 - 5 of 5 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy