Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How do I use sine to oscillate a variable….

  • How do I use sine to oscillate a variable….

    Posted by Erin Shelby on October 31, 2007 at 10:51 pm

    Pretty simple thing here, just wondering the best way to do it….

    I have a blur on something that I want to nicely (look like an ‘ease’ type move) from 0 to 3 to 0 to 3, etc… I know I could do something with “time” and “Math.sin” but for all my random expression writing, I don’t fundamentally know how to get from 0 to 3 nicely and change that variable knowing what is going on in terms of math.

    -E

    Nathan Goodfellow replied 8 years ago 5 Members · 9 Replies
  • 9 Replies
  • Rutger

    November 1, 2007 at 1:02 am

    Echo,

    1.5+1.5*Math.sin(Math.PI*time)

    the first 1.5 represents the average value, the 2nd 1.5 is the amplitude since 1.5+1.5=3 and 1.5-1.5 = 0 so it should oscillate between 0 and 3.

    if you don’t like the frequency which is 1 cycle per second, say you wanted 10 cycles per second, just change it to:

    1.5+1.5*Math.sin(Math.PI*10*time)

    That’s all

    Rutger

  • Erin Shelby

    November 1, 2007 at 1:06 pm

    Thanks so much, perfect explanation.

  • Darby Edelen

    November 1, 2007 at 2:28 pm

    [Rutger] “if you don’t like the frequency which is 1 cycle per second, say you wanted 10 cycles per second, just change it to:

    1.5+1.5*Math.sin(Math.PI*10*time)”

    Just a note, the period of sin(x) and cos(x) is 2 * Math.PI. So the frequency of the above expression is actually 5/second.

    Darby Edelen
    DVD Menu Artist
    Left Coast Digital
    Aptos, CA

  • Rutger

    November 1, 2007 at 10:33 pm

    Oopps…

    Yes I noticed the mistake, thanks for the catch.

    Rutger

  • Nathan Goodfellow

    April 26, 2018 at 1:53 am

    What if I want to do less cycles (slower cycles) say 1 cycle every 10 seconds. Do I divide the time?

    I’m attempting a random wave but 1 or more cycles per second was too much, I wanted to slow it down.

    Thank you for the help!

    (20+random(30))*Math.sin(Math.PI*(time/5))

  • Dan Ebberts

    April 26, 2018 at 6:19 am

    Something like this:

    freq = .25; // one cycle every 4 seconds
    (20+random(30))*Math.sin(time*freq*Math.PI*2)

    Dan

  • Nathan Goodfellow

    April 27, 2018 at 2:52 pm

    Thanks Dan! I’m giving this a try but I’m still not 100% happy with the results. I’m trying to use a random wave that is both a random wavelength and frequency. What I have so far is decent but its still moving too fast and I want to slow it down more. Any suggestions?

    (thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider")+40)+30*Math.sin(time*0.1*Math.PI*2)

  • Dan Ebberts

    April 27, 2018 at 4:18 pm

    I’m having a hard time picturing what you’re after exactly…

    Dan

  • Nathan Goodfellow

    April 27, 2018 at 5:40 pm

    Hey Dan,

    I know this sounds confusing but basically I’m looking to create a completely random wave… basically a squiggly line, so that the effect looks completely random the entire time, but not like wiggle (completely random) but rather a random curved line between different points (high and low wave)

    Does this make sense?

    Thank you so much for your time and help, this has already been extremely helpful… I feel like I’m fairly close to what I want to accomplish.

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