forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetWeightedAverage.as
More file actions
22 lines (19 loc) · 813 Bytes
/
getWeightedAverage.as
File metadata and controls
22 lines (19 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package utils.number {
/**
* Low pass filter algorithm for easing a value toward a destination value.
* Works best for tweening values when no definite time duration exists and
* when the destination value changes.
* When <code>(0.5 < n < 1)</code>, then the resulting values will
* overshoot (ping-pong) until they reach the destination value.
* When <code>n</code> is greater than 1, as its value increases, the time
* it takes to reach the destination also increases. A pleasing value for
* <code>n</code> is 5.
* @param value The current value.
* @param dest The destination value.
* @param n The slowdown factor.
* @return The weighted average.
*/
public function getWeightedAverage(value:Number, dest:Number, n:Number):Number {
return value + (dest - value) / n;
}
}