' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function allows you to do an exponential interpolation between two values.
'
' Pow# = A power of 1.0 will produce a linear tween.
' A power of 2.0 will cause the value to change slowly at first, then change quickly at the end.
' A power of 0.5 will do the opposite, causing the value to change quickly at first then slow down.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TweenExponential#(X1#, X2#, Tween#, Pow#=2.0)
Tween# = Tween#^Pow#
Return X1# + (Tween# * (X2# - X1#))
End Function
To use this pass the start and end position as X1 and X2, and call the function repeatedly, adjusting tween from 0..1 over linear time. The function outputs the position adjusted according to the specified exponent.
So with an exponent of 1, a tween of 0.5 would return the point in the midle of X1 and X2. But with an exponent of 2, a tween of 0.5 would return something quite a bit closer to X1 than X2, because that causes the point to move slower at the start.
You'll need to call the function twice each frame, once for the X axis, and once for the Y.
|