# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Loop undulations to length of comp

• # Loop undulations to length of comp

2 Members · 4 Posts
• ### trevor morgan

July 15, 2021 at 3:47 pm

Greetings,

I have a comp that is 7sec long with a layer that undulates up and down. I’m having trouble figuring out how to make the undulations loop to the comp length perfectly. I’m using the undulation expression via Dan’s motionscript.com site:

``````xAmp = 3; //height of undulations (pixels)
xFreq = .3; //undulations per second
xSpeed = 150; //speed of wave (pixels per second)

wl = xSpeed/xFreq; //wavelength (pixels)
phaseOffset = ((position[0]%wl)/wl)*2*Math.PI;
y = xAmp*Math.sin(2*Math.PI*xFreq*time + phaseOffset);
value + [0,y]``````

Any help with this greatly appreciated!

-Trevor

• ### Dan Ebberts

July 15, 2021 at 10:09 pm

I think you’d need to change xFreq to something that gives you a number of complete undulations over your 7 second comp duration. Try .286

• ### Dan Ebberts

July 15, 2021 at 11:35 pm

Actually, this is a better way to do it:

`xAmp = 50; //height of undulations (pixels)n = 2; // number of undulationsxFreq = n/thisComp.duration; // undulations per secondxSpeed = 150; //speed of wave (pixels per second)wl = xSpeed/xFreq; //wavelength (pixels)phaseOffset = ((position[0]%wl)/wl)*2*Math.PI;y = xAmp*Math.sin(2*Math.PI*xFreq*time + phaseOffset);value + [0,y]`
• ### trevor morgan

July 15, 2021 at 11:57 pm

SO FRICKIN STOKED!

totally works. Also works if I change the comp length. This is awesome!

Thank you so much

Viewing 1 - 4 of 4 posts