"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

1709926704329.png
 

Attachments

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

klaus

Expert
Licensed User
Longtime User
Top