ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# How do I use sine to oscillate a variable....

FAQ   •   VIEW ALL
 How do I use sine to oscillate a variable.... by echoon Oct 31, 2007 at 10:51:09 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

 Re: How do I use sine to oscillate a variable....by Rutgeron Nov 1, 2007 at 1:02:47 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

 Re: How do I use sine to oscillate a variable....by echoon Nov 1, 2007 at 1:06:04 pm

Thanks so much, perfect explanation.

 Re: How do I use sine to oscillate a variable....on Nov 1, 2007 at 2:28:22 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
Left Coast Digital
Aptos, CA

 Re: How do I use sine to oscillate a variable....by Rutgeron Nov 1, 2007 at 10:33:34 pm

Oopps...

Yes I noticed the mistake, thanks for the catch.

Rutger

 Re: How do I use sine to oscillate a variable....on Apr 26, 2018 at 1:53:42 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))`

 Re: How do I use sine to oscillate a variable....on Apr 26, 2018 at 6:19:33 am

Something like this:

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

Dan

 Re: How do I use sine to oscillate a variable....on Apr 27, 2018 at 2:52:58 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)`

 Re: How do I use sine to oscillate a variable....on Apr 27, 2018 at 4:18:38 pm

I'm having a hard time picturing what you're after exactly...

Dan

 Re: How do I use sine to oscillate a variable....on Apr 27, 2018 at 5:40:50 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.