Skip to main content
SpectacularKevin
Inspiring
August 1, 2020
Answered

Oscillating a single value between two numbers

  • August 1, 2020
  • 1 reply
  • 4692 views

This is very similar to my previous question, however, now I would like to do the same thing but on a single value suich as 'amount' or 'frequency' or 'transparency' I would like to be able to write an expression that will translate a value between two numbers evenly. Wiggle won't work because wiggle is random. Instead, I want to write an expression that allows that single value to oscillate back and forth between two values at the same speed and frequency.

 

For example:

If my 'amount' in glow is set to 20, I would like it to move evenly between 20 and 30. Like someone turning a dimmer switch up and down at the same speed and fequency. I would generally need this expression for a multitude of 'single values' in different effects. When I say 'single value' I mean it is not an X or Y but something singular like how transparency just has one value. 

This topic has been closed for replies.
Correct answer Dan Ebberts

Something like this should work:

 

minVal = 20;
maxVal = 30;
freq = 1; // oscillations per second
avgVal = (minVal + maxVal)/2;
amp = (maxVal - minVal)/2
avgVal + amp*(Math.sin(time*freq*Math.PI*2))

 

Dan

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
August 1, 2020

Something like this should work:

 

minVal = 20;
maxVal = 30;
freq = 1; // oscillations per second
avgVal = (minVal + maxVal)/2;
amp = (maxVal - minVal)/2
avgVal + amp*(Math.sin(time*freq*Math.PI*2))

 

Dan