Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to loop a Sin wave within X frames, starting at frame N?

  • How to loop a Sin wave within X frames, starting at frame N?

    Posted by Nicolas Hansen on May 29, 2009 at 2:54 am

    Ok so I have a slider that I want to apply a Math.sin() wave to.
    I want the wave to start at Frame 350 and Loop at 275 frames (so the value at Frame 350 is the same at Frame 625)
    It doesn’t matter if the slider value is 0 until frame 350, just as long as frame 350 and 625 are the same, because that span of frames is where I’ll have my loop. (I’d actually prefer if the sin wave started at frame 0 and went on forever)

    Actually, thinking about it now, as long as it loops for 275 frames, it doesn’t matter where it “starts” because by default, frame 350 and 625 will be the same value if it loops every 275 frames

    so having variables like this would be nice:
    loop = 275 // the amount of frames the sine wave takes to loop
    waves = 3 // the number of times the sine wave loops

    maybe even an “offset” variable for the number of frames to offset the sin wave by?

    I’ve been trying to read up on sine and cosine waves, but can’t seem to figure out how to change the duration of the loop
    Any suggestions?
    Thank you!

    Nicolas Hansen replied 16 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Nicolas Hansen

    May 29, 2009 at 3:08 am

    edit: nevermind I thought I had it.. it’s late X_X

  • Dan Ebberts

    May 29, 2009 at 3:14 am

    I think this does more or less what you want:

    dur = 275;
    startFrame = -75;

    radPerFrame = (Math.PI*2)/dur;
    Math.sin((timeToFrames()+startFrame)*radPerFrame)

    Dan

  • Nicolas Hansen

    May 29, 2009 at 3:17 am

    Ah, yes, thank you. I can fiddle with this. Thanks 🙂

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