"My favourite animation trick: exponential smoothing"

klaus

Expert
Licensed User
Longtime User
You may also have a look at this site: Easing Equations

And a B4XPages project using these equations, not tested with B4i, but the principles are the same.
I have used this kind of animation in the xRotaryKnob library, but inspired by a code from Erel in the Gauges thread.

To use only one equation you can change it in the AnimateTo routine.
The commented line is specific for CubicTimeEaseInOut.

B4X:
Private Sub AnimateTo(MoveFrom As Int, MoveTo As Int, Duration As Int)
    Private CurrentPosition As Int
    Private BeginTime As Long = DateTime.Now
   
    CurrentPosition = MoveTo
    Dim tempValueA As Float
    Do While DateTime.Now < BeginTime + Duration
        tempValueA = CallAnimation(DateTime.Now - BeginTime, MoveFrom, MoveTo - MoveFrom, Duration)
'        tempValueA = CubicTimeEaseInOut(DateTime.Now - BeginTime, MoveFrom, MoveTo - MoveFrom, Duration)
        DrawCircle(tempValueA)
        Sleep(5)
        If MoveTo <> CurrentPosition Then Return 'will happen if another update has started
    Loop
    DrawCircle(CurrentPosition)
End Sub

 

Attachments

  • Animations.zip
    32.5 KB · Views: 215
Last edited:

josejad

Expert
Licensed User
Longtime User
Please @klaus, post this wonderful example in some section of the forum. The chit chat forum is not indexed for searching.
 

klaus

Expert
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…