Abstract
In physics, a damped harmonic oscillator is a system that exhibits oscillatory motion (like a spring-mass system) but gradually loses its energy over time due to damping. This is similar to, for example, a swinging pendulum or other natural systems gradually coming to rest due to air resistance or a spring-mass system oscillating but eventually stopping due to friction.
Formula
Inertial Bounce
Where:
- A = amplitude (0.1)
- v = initial velocity
- f = frequency (2.0)
- d = decay rate (2.0)
- t = time since keyframe
Explained
amp = .1;
freq = 2.0;
decay = 2.0;
n = 0;
time_max = 4;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) {
n--;
}
}
if (n == 0) {
t = 0;
} else {
t = time - key(n).time;
}
if (n > 0 && t < time_max) {
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
value + v * amp * Math.sin(freq * t * 2 * Math.PI) / Math.exp(decay * t);
} else {
value
}
where:
- Variable Initialization:
amp = .1
: Sets the amplitude of a sine wave to 0.1.freq = 2.0
: Sets the frequency of the sine wave to 2.0.decay = 2.0
: Sets the decay rate to 2.0.n = 0
: Initializes the variable n to 0.time_max = 4
: Sets the maximum time to 4.
- Keyframe Handling:
- Checks if there are any keyframes
(numKeys > 0)
, if yes, it proceeds. - Finds the nearest keyframe index
(nearestKey(time).index)
relative to the current time. - Adjusts the keyframe index if the keyframe time is greater than the current time.
- Sets
t
to the difference between the current time and the time of the nearest keyframe.
- Value Calculation:
- If there are keyframes and t is within a certain range
(t < time_max)
, it proceeds. - Calculates the velocity at the time of the nearest keyframe
(velocityAtTime)
. - Calculates the new value using a sinusoidal function with amplitude amp, frequency
freq
, and a decay factordecay
. - The new value is calculated using the current value plus the velocity adjusted by the sine function and decay factor.
- If there are no keyframes or if t exceeds
time_max
, it returns the current value.
References
- Gray Machine: https://www.graymachine.com/top-5-effects-expressions