PB5.1 : Animation & Motion tween FX
Posted: Sun Feb 03, 2013 8:01 pm
I hope my convertion is correct 
I didn't test all functions.
Tween.pbi

I didn't test all functions.
Tween.pbi
Code: Select all
;-TOP
; Comment : Animation & Motion Tween
; Author : eddy
; Web : http://www.purebasic.fr/english/viewtopic.php?f=12&t=53251
; File: : Tween.pbi
; Version : v1.5
; Credit :
; Robert Penner - The easing equations we all know and love
; (http://robertpenner.com/easing/) [See License.txt for license info]
;
; Lee Brimelow - initial port of Penner's equations to WPF
; (http://thewpfblog.com/?p=12)
;
; Zeh Fernando - additional equations (out/in) from
; caurina.transitions.Tweener (http://code.google.com/p/tweener/)
; [See License.txt for license info]
EnableExplicit
; *********************
; ANIMATION & MOTION TWEEN
; *********************
;{ region Linear
; <summary>
; Easing equation function for a simple linear tweening, with no easing.
; </summary>
Procedure.f Tween_Linear( t.f, b.f, c.f, d.f )
ProcedureReturn c * t / d + b
EndProcedure
;} endregion
;{ region Expo
; <summary>
; Easing equation function for an exponential (2^t) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_ExpoEaseOut( t.f, b.f, c.f, d.f )
If ( t = d ) : ProcedureReturn b + c : Else : ProcedureReturn c * ( -Pow( 2, -10 * t / d ) + 1 ) + b : EndIf
EndProcedure
; <summary>
; Easing equation function for an exponential (2^t) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_ExpoEaseIn( t.f, b.f, c.f, d.f )
If ( t = 0 ) : ProcedureReturn b : Else : ProcedureReturn c * Pow( 2, 10 * ( t / d - 1 ) ) + b : EndIf
EndProcedure
; <summary>
; Easing equation function for an exponential (2^t) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_ExpoEaseInOut( t.f, b.f, c.f, d.f )
If ( t = 0 )
ProcedureReturn b;
EndIf
If ( t = d )
ProcedureReturn b + c;
EndIf
t / (d / 2)
If ( t < 1 )
ProcedureReturn c / 2 * Pow( 2, 10 * ( t - 1 ) ) + b;
EndIf
t-1
ProcedureReturn c / 2 * ( -Pow( 2, -10 * t ) + 2 ) + b
EndProcedure
; <summary>
; Easing equation function for an exponential (2^t) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_ExpoEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_ExpoEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_ExpoEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Circular
; <summary>
; Easing equation function for a circular (sqrt(1-t^2)) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_CircEaseOut( t.f, b.f, c.f, d.f )
t = t / d - 1
ProcedureReturn c * Sqr( 1 - t * t ) + b
EndProcedure
; <summary>
; Easing equation function for a circular (sqrt(1-t^2)) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_CircEaseIn( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn -c * ( Sqr( 1 - t * t ) - 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a circular (sqrt(1-t^2)) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_CircEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t < 1 )
ProcedureReturn -c / 2 * ( Sqr( 1 - t * t ) - 1 ) + b;
EndIf
t - 2
ProcedureReturn c / 2 * ( Sqr( 1 - t * t ) + 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a circular (sqrt(1-t^2)) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_CircEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_CircEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_CircEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Quad
; <summary>
; Easing equation function for a quadratic (t^2) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_QuadEaseOut( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn -c * t * ( t - 2 ) + b
EndProcedure
; <summary>
; Easing equation function for a quadratic (t^2) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_QuadEaseIn( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn c * t * t + b
EndProcedure
; <summary>
; Easing equation function for a quadratic (t^2) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_QuadEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t < 1 )
ProcedureReturn c / 2 * t * t + b;
EndIf
t-1
ProcedureReturn -c / 2 * ( t * ( t - 2 ) - 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a quadratic (t^2) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_QuadEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_QuadEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_QuadEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Sine
; <summary>
; Easing equation function for a sinusoidal (sin(t)) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_SineEaseOut( t.f, b.f, c.f, d.f )
ProcedureReturn c * Sin( t / d * ( #PI / 2 ) ) + b
EndProcedure
; <summary>
; Easing equation function for a sinusoidal (sin(t)) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_SineEaseIn( t.f, b.f, c.f, d.f )
ProcedureReturn -c * Cos( t / d * ( #PI / 2 ) ) + c + b
EndProcedure
; <summary>
; Easing equation function for a sinusoidal (sin(t)) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_SineEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t < 1 )
ProcedureReturn c / 2 * ( Sin( #PI * t / 2 ) ) + b;
EndIf
t-1
ProcedureReturn -c / 2 * ( Cos( #PI * t / 2 ) - 2 ) + b
EndProcedure
; <summary>
; Easing equation function for a sinusoidal (sin(t)) easing in/out:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_SineEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_SineEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_SineEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Cubic
; <summary>
; Easing equation function for a cubic (t^3) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_CubicEaseOut( t.f, b.f, c.f, d.f )
t = t / d - 1
ProcedureReturn c * ( t * t * t + 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a cubic (t^3) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_CubicEaseIn( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn c * t * t * t + b
EndProcedure
; <summary>
; Easing equation function for a cubic (t^3) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_CubicEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t < 1 )
ProcedureReturn c / 2 * t * t * t + b;
EndIf
t - 2
ProcedureReturn c / 2 * ( t * t * t + 2 ) + b
EndProcedure
; <summary>
; Easing equation function for a cubic (t^3) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_CubicEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_CubicEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_CubicEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Quartic
; <summary>
; Easing equation function for a quartic (t^4) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_QuartEaseOut( t.f, b.f, c.f, d.f )
t = t / d - 1
ProcedureReturn -c * ( t * t * t * t - 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a quartic (t^4) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_QuartEaseIn( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn c * t * t * t * t + b
EndProcedure
; <summary>
; Easing equation function for a quartic (t^4) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_QuartEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t < 1 )
ProcedureReturn c / 2 * t * t * t * t + b;
EndIf
t - 2
ProcedureReturn -c / 2 * ( t * t * t * t - 2 ) + b
EndProcedure
; <summary>
; Easing equation function for a quartic (t^4) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_QuartEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_QuartEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_QuartEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Quintic
; <summary>
; Easing equation function for a quintic (t^5) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_QuintEaseOut( t.f, b.f, c.f, d.f )
t = t / d - 1
ProcedureReturn c * ( t * t * t * t * t + 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a quintic (t^5) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_QuintEaseIn( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn c * t * t * t * t * t + b
EndProcedure
; <summary>
; Easing equation function for a quintic (t^5) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_QuintEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t < 1 )
ProcedureReturn c / 2 * t * t * t * t * t + b;
EndIf
t - 2
ProcedureReturn c / 2 * ( t * t * t * t * t + 2 ) + b
EndProcedure
; <summary>
; Easing equation function for a quintic (t^5) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_QuintEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_QuintEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_QuintEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Elastic
; <summary>
; Easing equation function for an elastic (exponentially decaying sine wave) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_ElasticEaseOut( t.f, b.f, c.f, d.f )
t / d
If ( t = 1 )
ProcedureReturn b + c;
EndIf
Protected p.f = d * 0.3
Protected s.f = p / 4
ProcedureReturn ( c * Pow( 2, -10 * t ) * Sin( ( t * d - s ) * ( 2 * #PI ) / p ) + c + b )
EndProcedure
; <summary>
; Easing equation function for an elastic (exponentially decaying sine wave) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_ElasticEaseIn( t.f, b.f, c.f, d.f )
t / d
If ( t = 1 )
ProcedureReturn b + c;
EndIf
Protected p.f = d * 0.3
Protected s.f = p / 4
t - 1
ProcedureReturn -( c * Pow( 2, 10 * t ) * Sin( ( t * d - s ) * ( 2 * #PI ) / p ) ) + b
EndProcedure
; <summary>
; Easing equation function for an elastic (exponentially decaying sine wave) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_ElasticEaseInOut( t.f, b.f, c.f, d.f )
t / (d / 2)
If ( t = 2 )
ProcedureReturn b + c;
EndIf
Protected p.f = d * ( 0.3 * 1.5 )
Protected s.f = p / 4
If ( t < 1 )
t - 1
ProcedureReturn -0.5 * ( c * Pow( 2, 10 * t ) * Sin( ( t * d - s ) * ( 2 * #PI ) / p ) ) + b;
EndIf
t - 1
ProcedureReturn c * Pow( 2, -10 * t ) * Sin( ( t * d - s ) * ( 2 * #PI ) / p ) * 0.5 + c + b
EndProcedure
; <summary>
; Easing equation function for an elastic (exponentially decaying sine wave) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_ElasticEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_ElasticEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_ElasticEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Bounce
; <summary>
; Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_BounceEaseOut( t.f, b.f, c.f, d.f )
t / d
If ( t < ( 1 / 2.75 ) )
ProcedureReturn c * ( 7.5625 * t * t ) + b;
ElseIf ( t < ( 2 / 2.75 ) )
t - ( 1.5 / 2.75 )
ProcedureReturn c * ( 7.5625 * t * t + 0.75 ) + b;
ElseIf ( t < ( 2.5 / 2.75 ) )
t - ( 2.25 / 2.75 )
ProcedureReturn c * ( 7.5625 * t * t + 0.9375 ) + b;
Else
t - ( 2.625 / 2.75 )
ProcedureReturn c * ( 7.5625 * t * t + 0.984375 ) + b
EndIf
EndProcedure
; <summary>
; Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_BounceEaseIn( t.f, b.f, c.f, d.f )
ProcedureReturn c - Tween_BounceEaseOut( d - t, 0, c, d ) + b
EndProcedure
; <summary>
; Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_BounceEaseInOut( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_BounceEaseIn( t * 2, 0, c, d ) * 0.5 + b;
Else
ProcedureReturn Tween_BounceEaseOut( t * 2 - d, 0, c, d ) * 0.5 + c * 0.5 + b
EndIf
EndProcedure
; <summary>
; Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_BounceEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_BounceEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_BounceEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
;{ region Back
; <summary>
; Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out:
; decelerating from zero velocity.
; </summary>
Procedure.f Tween_BackEaseOut( t.f, b.f, c.f, d.f )
t = t / d - 1
ProcedureReturn c * ( t * t * ( ( 1.70158 + 1 ) * t + 1.70158 ) + 1 ) + b
EndProcedure
; <summary>
; Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in:
; accelerating from zero velocity.
; </summary>
Procedure.f Tween_BackEaseIn( t.f, b.f, c.f, d.f )
t / d
ProcedureReturn c * t * t * ( ( 1.70158 + 1 ) * t - 1.70158 ) + b
EndProcedure
; <summary>
; Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out:
; acceleration until halfway, then deceleration.
; </summary>
Procedure.f Tween_BackEaseInOut( t.f, b.f, c.f, d.f )
Protected s.f = 1.70158
t / (d / 2)
If ( t < 1 )
s * ( 1.525 )
ProcedureReturn c / 2 * ( t * t * ( ( s + 1 ) * t - s ) ) + b;
EndIf
t - 2
s * ( 1.525 )
ProcedureReturn c / 2 * ( t * t * ( ( s + 1 ) * t + s ) + 2 ) + b
EndProcedure
; <summary>
; Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in:
; deceleration until halfway, then acceleration.
; </summary>
Procedure.f Tween_BackEaseOutIn( t.f, b.f, c.f, d.f )
If ( t < d / 2 )
ProcedureReturn Tween_BackEaseOut( t * 2, b, c / 2, d );
EndIf
ProcedureReturn Tween_BackEaseIn( ( t * 2 ) - d, b + c / 2, c / 2, d )
EndProcedure
;} endregion
Enumeration
;Tween FX list
#FX_Linear=0
#FX_QuadEaseOut
#FX_QuadEaseIn
#FX_QuadEaseInOut
#FX_QuadEaseOutIn
#FX_ExpoEaseOut
#FX_ExpoEaseIn
#FX_ExpoEaseInOut
#FX_ExpoEaseOutIn
#FX_CubicEaseOut
#FX_CubicEaseIn
#FX_CubicEaseInOut
#FX_CubicEaseOutIn
#FX_QuartEaseOut
#FX_QuartEaseIn
#FX_QuartEaseInOut
#FX_QuartEaseOutIn
#FX_QuintEaseOut
#FX_QuintEaseIn
#FX_QuintEaseInOut
#FX_QuintEaseOutIn
#FX_CircEaseOut
#FX_CircEaseIn
#FX_CircEaseInOut
#FX_CircEaseOutIn
#FX_SineEaseOut
#FX_SineEaseIn
#FX_SineEaseInOut
#FX_SineEaseOutIn
#FX_ElasticEaseOut
#FX_ElasticEaseIn
#FX_ElasticEaseInOut
#FX_ElasticEaseOutIn
#FX_BounceEaseOut
#FX_BounceEaseIn
#FX_BounceEaseInOut
#FX_BounceEaseOutIn
#FX_BackEaseOut
#FX_BackEaseIn
#FX_BackEaseInOut
#FX_BackEaseOutIn
;Helpers to select all FX in FOR...NEXT loops
#FX_FirstValue=#FX_Linear
#FX_LastValue=#FX_BackEaseOutIn
;Looping mode
#FX_Loop_Cycle=0
#FX_Loop_PingPong
;Looping count max
#FX_Loop_MaxCount=$FFFF
;Helpers to change FastTween Accuracy
#FX_FastTweenResolution=2048
#FX_FastTweenPingPong=#FX_FastTweenResolution*2
EndEnumeration
Global Dim FastTweenValues.f(#FX_LastValue,#FX_FastTweenResolution)
Global Dim FastTweenCycles.u(#FX_FastTweenPingPong)
Procedure.f Tween(fx, timer.f, start.f, delta.f, duration.f)
Select fx
Case #FX_Linear: ProcedureReturn Tween_Linear(timer, start, delta, duration)
Case #FX_QuadEaseOut: ProcedureReturn Tween_QuadEaseOut(timer, start, delta, duration)
Case #FX_QuadEaseIn: ProcedureReturn Tween_QuadEaseIn(timer, start, delta, duration)
Case #FX_QuadEaseInOut: ProcedureReturn Tween_QuadEaseInOut(timer, start, delta, duration)
Case #FX_QuadEaseOutIn: ProcedureReturn Tween_QuadEaseOutIn(timer, start, delta, duration)
Case #FX_ExpoEaseOut: ProcedureReturn Tween_ExpoEaseOut(timer, start, delta, duration)
Case #FX_ExpoEaseIn: ProcedureReturn Tween_ExpoEaseIn(timer, start, delta, duration)
Case #FX_ExpoEaseInOut: ProcedureReturn Tween_ExpoEaseInOut(timer, start, delta, duration)
Case #FX_ExpoEaseOutIn: ProcedureReturn Tween_ExpoEaseOutIn(timer, start, delta, duration)
Case #FX_CubicEaseOut: ProcedureReturn Tween_CubicEaseOut(timer, start, delta, duration)
Case #FX_CubicEaseIn: ProcedureReturn Tween_CubicEaseIn(timer, start, delta, duration)
Case #FX_CubicEaseInOut: ProcedureReturn Tween_CubicEaseInOut(timer, start, delta, duration)
Case #FX_CubicEaseOutIn: ProcedureReturn Tween_CubicEaseOutIn(timer, start, delta, duration)
Case #FX_QuartEaseOut: ProcedureReturn Tween_QuartEaseOut(timer, start, delta, duration)
Case #FX_QuartEaseIn: ProcedureReturn Tween_QuartEaseIn(timer, start, delta, duration)
Case #FX_QuartEaseInOut: ProcedureReturn Tween_QuartEaseInOut(timer, start, delta, duration)
Case #FX_QuartEaseOutIn: ProcedureReturn Tween_QuartEaseOutIn(timer, start, delta, duration)
Case #FX_QuintEaseOut: ProcedureReturn Tween_QuintEaseOut(timer, start, delta, duration)
Case #FX_QuintEaseIn: ProcedureReturn Tween_QuintEaseIn(timer, start, delta, duration)
Case #FX_QuintEaseInOut: ProcedureReturn Tween_QuintEaseInOut(timer, start, delta, duration)
Case #FX_QuintEaseOutIn: ProcedureReturn Tween_QuintEaseOutIn(timer, start, delta, duration)
Case #FX_CircEaseOut: ProcedureReturn Tween_CircEaseOut(timer, start, delta, duration)
Case #FX_CircEaseIn: ProcedureReturn Tween_CircEaseIn(timer, start, delta, duration)
Case #FX_CircEaseInOut: ProcedureReturn Tween_CircEaseInOut(timer, start, delta, duration)
Case #FX_CircEaseOutIn: ProcedureReturn Tween_CircEaseOutIn(timer, start, delta, duration)
Case #FX_SineEaseOut: ProcedureReturn Tween_SineEaseOut(timer, start, delta, duration)
Case #FX_SineEaseIn: ProcedureReturn Tween_SineEaseIn(timer, start, delta, duration)
Case #FX_SineEaseInOut: ProcedureReturn Tween_SineEaseInOut(timer, start, delta, duration)
Case #FX_SineEaseOutIn: ProcedureReturn Tween_SineEaseOutIn(timer, start, delta, duration)
Case #FX_ElasticEaseOut: ProcedureReturn Tween_ElasticEaseOut(timer, start, delta, duration)
Case #FX_ElasticEaseIn: ProcedureReturn Tween_ElasticEaseIn(timer, start, delta, duration)
Case #FX_ElasticEaseInOut: ProcedureReturn Tween_ElasticEaseInOut(timer, start, delta, duration)
Case #FX_ElasticEaseOutIn: ProcedureReturn Tween_ElasticEaseOutIn(timer, start, delta, duration)
Case #FX_BounceEaseOut: ProcedureReturn Tween_BounceEaseOut(timer, start, delta, duration)
Case #FX_BounceEaseIn: ProcedureReturn Tween_BounceEaseIn(timer, start, delta, duration)
Case #FX_BounceEaseInOut: ProcedureReturn Tween_BounceEaseInOut(timer, start, delta, duration)
Case #FX_BounceEaseOutIn: ProcedureReturn Tween_BounceEaseOutIn(timer, start, delta, duration)
Case #FX_BackEaseOut: ProcedureReturn Tween_BackEaseOut(timer, start, delta, duration)
Case #FX_BackEaseIn: ProcedureReturn Tween_BackEaseIn(timer, start, delta, duration)
Case #FX_BackEaseInOut: ProcedureReturn Tween_BackEaseInOut(timer, start, delta, duration)
Case #FX_BackEaseOutIn: ProcedureReturn Tween_BackEaseOutIn(timer, start, delta, duration)
EndSelect
EndProcedure
Procedure.f FastTween(fx, timer.f, start.f, delta.f, duration.f)
Protected tweenIndex=Int(#FX_FastTweenResolution*timer/duration)
If tweenIndex>#FX_FastTweenResolution
ProcedureReturn delta+start
EndIf
ProcedureReturn FastTweenValues(fx,tweenIndex)*delta+start
EndProcedure
Procedure.f FastTweenLoop(fx, timer.f, start.f, delta.f, duration.f, loopMode, loopCount.f=#FX_Loop_MaxCount)
Protected tweenIndex=Int(#FX_FastTweenResolution*timer/duration)
Select loopMode
Case #FX_Loop_Cycle
If timer>#FX_FastTweenResolution*loopCount
tweenIndex=#FX_FastTweenResolution*loopCount
EndIf
tweenIndex % (#FX_FastTweenResolution+1)
Case #FX_Loop_PingPong
If timer>#FX_FastTweenResolution*loopCount*2
tweenIndex=#FX_FastTweenResolution*loopCount*2
EndIf
tweenIndex=FastTweenCycles(tweenIndex % (#FX_FastTweenPingPong+1))
EndSelect
ProcedureReturn FastTweenValues(fx,tweenIndex)*delta+start
EndProcedure
Procedure InitFastTween()
Protected fx,t
For fx=#FX_FirstValue To #FX_LastValue
For t=0 To #FX_FastTweenResolution
FastTweenValues(fx,t)=Tween(fx,t,0,1,#FX_FastTweenResolution)
Next
Next
For t=0 To #FX_FastTweenResolution
FastTweenCycles(t)=t
FastTweenCycles(#FX_FastTweenPingPong-t)=t
Next
EndProcedure
Procedure.i DeltaMilliseconds()
Static lastTime.i, previousTime.i, deltaTime.f
lastTime=ElapsedMilliseconds()
deltaTime=(lastTime-previousTime)
previousTime=lastTime
ProcedureReturn deltaTime
EndProcedure
Procedure.f DeltaSeconds()
Static lastTime.i, previousTime.i, deltaTime.f
lastTime=ElapsedMilliseconds()
deltaTime=(lastTime-previousTime)
previousTime=lastTime
ProcedureReturn deltaTime/1000.0
EndProcedure