Highlighted

## Oscillating a single value between two numbers

Community Beginner ,
Aug 01, 2020

Copied

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.

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

TOPICS
Expressions

Views

59

Likes

Report

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

## Oscillating a single value between two numbers

Community Beginner ,
Aug 01, 2020

Copied

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.

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

TOPICS
Expressions

Views

60

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 01, 2020 0
Guide ,
Aug 01, 2020

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 01, 2020 1
Resources
Troubleshooting FAQs
After Effects Community Recap
Getting started with After Effects