Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Finding a loop point in an Expression

  • Finding a loop point in an Expression

    Posted by David Rodriguez on June 28, 2008 at 5:09 pm

    I am using the following on position

    xAmp = 30; //height of undulations (pixels)
    xFreq = .8; //undulations per second
    xSpeed = 350; //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);

    swayAmp = 50; //amplitude of sway
    swayFreq = 2; //frequency of sway
    x = swayAmp * Math.sin(time * swayFreq);

    value + [x,y]

    and the following on rotation

    xFreq = .5; //undulations per second
    xSpeed = 150; //speed of wave (pixels per second)
    damping = 12; //undulation damping factor

    wl = xSpeed/xFreq; //wavelength (pixels)
    phaseOffset = ((position[0]%wl)/wl)*2*Math.PI;
    theta = Math.atan(Math.cos(2*Math.PI*xFreq*time + phaseOffset));
    radiansToDegrees(theta)/damping;

    Is there any way to make these expressions loopable? I would like the position and rotation to come back to the original starting point so that it makes a perfect loop cycle.

    Any help would be greatly appreciated!

    Dan Ebberts replied 17 years, 10 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    June 28, 2008 at 9:33 pm

    I think you’d need to pick your 3 frequencies so that they are harmonically related to get any kind of reasonable loop time. Right now you have two true “frequency” values (where you have the Math.PI*2 multiplier in the wave calc) and one where you haven’t done that, so I think the calculation for how often the waves all get back to their starting positions at the same time will be ugly.

    Let’s say you set it up where your frequencies are 1, .5, and 1/3 (for example). That gives you periods of 1 sec, 2 sec, and 3 sec. The lowest common denominator for that would be 6 sec, so your animation would loop every six seconds.

    Dan

  • David Rodriguez

    June 29, 2008 at 2:16 am

    [Dan Ebberts] “Right now you have two true “frequency” values (where you have the Math.PI*2 multiplier in the wave calc) and one where you haven’t done that…”

    Is it the sway frequency that lacks the Math.PI*2 multiplier?
    Can I change the math in that part to match the others?
    I am confused here, sorry for my lack of understanding in this area.

  • Dan Ebberts

    June 29, 2008 at 6:43 pm

    Yes. If you changed it from this:

    x = swayAmp * Math.sin(time * swayFreq);

    to this:

    x = swayAmp * Math.sin(time * swayFreq * Math.PI * 2);

    and changed swayFreq to .25, then you’d have .8, .5, and .25 which should repeat every 4 seconds (I think) 🙂

    Dan

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