Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Oscillating a single value between two numbers

Explorer ,
Aug 01, 2020 Aug 01, 2020

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. 

TOPICS
Expressions
4.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 01, 2020 Aug 01, 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

Translate
Community Expert ,
Aug 01, 2020 Aug 01, 2020
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines