Modify Vb.Net Code of Animation

0

Hello.
I was trying to convert the next following code to something like this:

Class Animation  

    Public Property Inicio as TimeSpan = Now.TimeOfDay  
    Public Property Duration as TimeSpan = New TimeSpan(0,0,5)  
    Public Property Tipo As TipoAnimacion = TypeTransition.EaseInBack

    Public Property Minimun As Integer = 10
    Public Property Maximun As Integer = 100

    Public Function GetValue(ByVal TheTimeOfNow As TimeSpan) As Integer

        ' Si (TheTimeOfNow = Inicio) Entonces 'La animacion recien comienza
        '     Devolver Minimun
        ' Sino Si (TheTimeOfNow >= (Inicio + Duration)) 'La animacion termina o ya finalizo antes
        '     Devolver Maximun
        ' Sino
        '     Devolver <<Formula matemática ya calculada>>
        ' Fin Si

        return ...?
    End Function 
End Class

Current code: (It works)

Public Class Animation


Inherits Timer

Private _Objet As Object
Private _NomPropiedad As String
Private _Type As String
Private _Inicio As Integer
Private _Final As Integer
Private _Duracion As Integer ' En Milisegundos
Private _AccionPorSegundo As Integer

Private t As Double
Private NumeroIteracion As Integer
Private InteracionEnProgreso As Integer
Private Intercambio As Integer

Public Property Inicio() As Integer

    Get
        Return _Inicio
    End Get
    Set(ByVal value As Integer)
        _Inicio = value
    End Set

End Property

Public Property Final() As Integer

    Get
        Return _Final
    End Get

    Set(ByVal value As Integer)

        _Final = value

        Intercambio = _Final - _Inicio

    End Set

End Property

Public Property Duracion() As Integer

    Get
        Return _Duracion
    End Get
    Set(ByVal value As Integer)

        _Duracion = value

        NumeroIteracion = Math.Round(_Duracion / _AccionPorSegundo, 0)

    End Set
End Property

Public Property AccionPorSegundo() As Integer

    Get
        Return _AccionPorSegundo
    End Get

    Set(ByVal value As Integer)

        _AccionPorSegundo = value

        Me.Interval = _AccionPorSegundo

        NumeroIteracion = Math.Round(_Duracion / _AccionPorSegundo, 0)

    End Set
End Property

Public Property Type() As TypeTransition

    Get
        Return _Type
    End Get

    Set(ByVal value As TypeTransition)
        _Type = value
    End Set

End Property

Public Property Objet() As Object

    Get
        Return _Objet
    End Get

    Set(ByVal value As Object)

        _Objet = value

    End Set

End Property

Public Property NomPropriedad() As String

    Get
        Return _NomPropiedad
    End Get

    Set(ByVal value As String)

        _NomPropiedad = value

    End Set

End Property

Sub Transition(ByVal m_objet As Object, ByVal m_NomPropriete As String, ByVal m_Type As TypeTransition, ByVal m_Debut As Integer, ByVal m_Fin As Integer, ByVal m_Duree As Integer)

    Me.Objet = m_objet
    Me.NomPropriedad = m_NomPropriete
    Me.Type = m_Type
    Me.Inicio = m_Debut
    Me.Final = m_Fin
    Me.Duracion = m_Duree

    AddHandler Me.Tick, AddressOf ActualizarPropiedad

    Me.Start()

End Sub

Private Sub ActualizarPropiedad()

    Me.Actualizar()

    CallByName(_Objet, _NomPropiedad, CallType.Set, Me.Easing())

End Sub

Public Sub New()

    ' Par défaut 
    AccionPorSegundo = 20
    InteracionEnProgreso = 0
    Me.Enabled = True

End Sub

Public Sub Actualizar()

    InteracionEnProgreso = InteracionEnProgreso + 1

    t = Me.InteracionEnProgreso / Me.NumeroIteracion

End Sub

Function Easing() As Double

    If InteracionEnProgreso > NumeroIteracion Then

        Me.Stop()

    End If

    Easing = EasingFunctions(_Type, t, Inicio, Intercambio, 1)

End Function

Enum TypeTransition
    easeInBack
    easeInBounce
    easeOutBounce
    easeInOutBounce
    easeInCirc
    easeInCubic
    easeInElastic
    easeInExpo
    easeInOutBack
    easeInOutCirc
    easeInOutCubic
    easeInOutElastic
    easeInOutExpo
    easeInOutQuad
    easeInOutQuart
    easeInOutQuint
    easeInOutSine
    easeInQuad
    easeInQuart
    easeInQuint
    easeInSine
    easeOutBack
    easeOutCirc
    easeOutCubic
    easeOutElastic
    easeOutExpo
    easeOutQuad
    easeOutQuart
    easeOutQuint
    easeOutSine
End Enum



Shared Function EasingFunctions(ByVal mode As String, ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Select Case (mode)

        Case TypeTransition.easeInBack

            EasingFunctions = easeInBack(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInBounce

            EasingFunctions = easeInBounce(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutBounce

            EasingFunctions = easeOutBounce(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutBounce

            EasingFunctions = easeInOutBounce(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInCirc

            EasingFunctions = easeInCirc(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInCubic
            EasingFunctions = easeInCubic(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInElastic

            EasingFunctions = easeInElastic(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInExpo

            EasingFunctions = easeInExpo(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutBack
            EasingFunctions = easeInOutBack(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutCirc

            EasingFunctions = easeInOutCirc(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutCubic

            EasingFunctions = easeInOutCubic(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutElastic

            EasingFunctions = easeInOutElastic(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutExpo
            EasingFunctions = easeInOutExpo(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutQuad

            EasingFunctions = easeInOutQuad(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutQuart

            EasingFunctions = easeInOutQuart(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutQuint

            EasingFunctions = easeInOutQuint(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInOutSine

            EasingFunctions = easeInOutSine(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInQuad

            EasingFunctions = easeInQuad(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInQuart

            EasingFunctions = easeInQuart(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInQuint

            EasingFunctions = easeInQuint(t, b, c, d)
            Exit Function

        Case TypeTransition.easeInSine

            EasingFunctions = easeInSine(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutBack

            EasingFunctions = easeOutBack(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutCirc

            EasingFunctions = easeOutCirc(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutCubic

            EasingFunctions = easeOutCubic(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutElastic

            EasingFunctions = easeOutElastic(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutExpo

            EasingFunctions = easeOutExpo(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutQuad

            EasingFunctions = easeOutQuad(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutQuart

            EasingFunctions = easeOutQuart(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutQuint

            EasingFunctions = easeOutQuint(t, b, c, d)
            Exit Function

        Case TypeTransition.easeOutSine

            EasingFunctions = easeOutSine(t, b, c, d)
            Exit Function

        Case Else

            EasingFunctions = -1

    End Select

End Function

Shared Function easeInQuad(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d
    easeInQuad = c * t * t + b

End Function

Shared Function easeOutQuad(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d
    easeOutQuad = -c * t * (t - 2) + b

End Function

Shared Function easeInOutQuad(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = 2 * t / d

    If t < 1 Then
        '
        easeInOutQuad = (c / 2) * t * t + b

    Else

        t = t - 1

        easeInOutQuad = -c / 2 * (t * (t - 2) - 1) + b

    End If

End Function

Shared Function easeInCubic(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d
    easeInCubic = c * (t) * t * t + b

End Function

Shared Function easeOutCubic(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = (t / d) - 1

    easeOutCubic = c * (t * t * t + 1) + b

End Function

Shared Function easeInOutCubic(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = 2 * t / d
    If (t < 1) Then
        easeInOutCubic = c / 2 * t * t * t + b
    Else
        t = t - 2
        easeInOutCubic = c / 2 * (t * t * t + 2) + b
    End If

End Function

Shared Function easeInQuart(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d
    easeInQuart = c * t * t * t * t + b

End Function

Shared Function easeOutQuart(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d - 1
    easeOutQuart = -c * ((t * t * t * t) - 1) + b

End Function

Shared Function easeInOutQuart(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = 2 * t / d

    If (t < 1) Then
        easeInOutQuart = c / 2 * t * t * t * t + b
    Else
        t = t - 2
        easeInOutQuart = -c / 2 * (t * t * t * t - 2) + b
    End If

End Function

Shared Function easeInQuint(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d
    easeInQuint = c * t * t * t * t * t + b

End Function

Shared Function easeOutQuint(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d - 1
    easeOutQuint = c * (t * t * t * t * t + 1) + b

End Function

Shared Function easeInOutQuint(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = 2 * t / d
    If (t < 1) Then
        easeInOutQuint = c / 2 * t * t * t * t * t + b
    Else
        t = t - 2
        easeInOutQuint = c / 2 * (t * t * t * t * t + 2) + b
    End If

End Function

Shared Function easeInSine(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    easeInSine = -c * Math.Cos((t / d) * (Math.PI / 2)) + c + b

End Function

Shared Function easeOutSine(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    easeOutSine = c * Math.Sin(t / d * (Math.PI / 2)) + b

End Function

Shared Function easeInOutSine(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    easeInOutSine = -c / 2 * (Math.Cos(Math.PI * t / d) - 1) + b

End Function

Shared Function easeInExpo(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    If t = 0 Then
        easeInExpo = b
    Else
        easeInExpo = c * Math.Pow(2, 10 * (t / d - 1)) + b
    End If

End Function

Shared Function easeOutExpo(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    If t = d Then
        easeOutExpo = b + c
    Else
        easeOutExpo = c * (-Math.Pow(2, -10 * t / d) + 1) + b
    End If

End Function

Shared Function easeInOutExpo(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    If t = 0 Then
        easeInOutExpo = b
        Exit Function
    End If

    If t = d Then
        easeInOutExpo = b + c
        Exit Function
    End If

    t = 2 * t / d
    If t < 1 Then
        easeInOutExpo = c / 2 * Math.Pow(2, 10 * (t - 1)) + b
    Else
        t = t - 1
        easeInOutExpo = c / 2 * (-Math.Pow(2, -10 * t) + 2) + b
    End If

End Function

Shared Function easeInCirc(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d
    easeInCirc = -c * (Math.Sqrt(1 - (t * t)) - 1) + b

End Function

Shared Function easeOutCirc(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = t / d - 1
    easeOutCirc = c * Math.Sqrt(1 - (t * t)) + b

End Function

Shared Function easeInOutCirc(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    t = 2 * t / d
    If t < 1 Then
        easeInOutCirc = -c / 2 * (Math.Sqrt(1 - t * t) - 1) + b
    Else
        t = t - 2
        easeInOutCirc = c / 2 * (Math.Sqrt(1 - t * t) + 1) + b
    End If

End Function

Shared Function easeInElastic(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Dim s As Double = 1.70158
    Dim p As Double = 0
    Dim a As Double = c

    If t = 0 Then
        easeInElastic = b
        Exit Function
    End If

    t = t / d
    If t = 1 Then
        easeInElastic = b + c
        Exit Function
    End If

    p = d * 0.3

    If (a < Math.Abs(c)) Then
        a = c
        s = p / 4
    Else
        s = p / (2 * Math.PI) * Math.Asin(c / a)
    End If

    t = t - 1
    easeInElastic = -(a * Math.Pow(2, 10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b

End Function

Shared Function easeOutElastic(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Dim s As Double = 1.70158
    Dim p As Double = 0
    Dim a As Double = c

    If t = 0 Then
        easeOutElastic = b
        Exit Function
    End If

    t = t / d
    If t = 1 Then
        easeOutElastic = b + c
        Exit Function
    End If

    p = d * 0.3

    If (a < Math.Abs(c)) Then
        a = c
        s = p / 4
    Else
        s = p / (2 * Math.PI) * Math.Asin(c / a)
    End If

    easeOutElastic = a * Math.Pow(2, -10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p) + c + b

End Function

Shared Function easeInOutElastic(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Dim s As Double = 1.70158
    Dim p As Double = 0
    Dim a As Double = c

    If t = 0 Then
        easeInOutElastic = b
        Exit Function
    End If

    t = 2 * t / d
    If t = 2 Then
        easeInOutElastic = b + c
        Exit Function
    End If

    p = d * 0.3 * 1.5

    If (a < Math.Abs(c)) Then
        a = c
        s = p / 4
    Else
        s = p / (2 * Math.PI) * Math.Asin(c / a)
    End If

    If t < 1 Then
        t = t - 1
        easeInOutElastic = -0.5 * (a * Math.Pow(2, 10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b
    Else
        t = t - 1
        easeInOutElastic = a * Math.Pow(2, -10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b
    End If

End Function

Shared Function easeInBack(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Dim s As Double
    s = 1.70158
    t = t / d
    easeInBack = c * t * t * ((s + 1) * t - s) + b

End Function

Shared Function easeOutBack(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Dim s As Double
    s = 1.70158
    t = t / d - 1
    easeOutBack = c * (t * t * ((s + 1) * t + s) + 1) + b

End Function

Shared Function easeInOutBack(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    Dim s As Double
    s = 1.70158

    t = 2 * t / d

    If t < 1 Then
        s = s * 1.525
        easeInOutBack = c / 2 * (t * t * (((s) + 1) * t - s)) + b
    Else
        t = t - 2
        easeInOutBack = c / 2 * ((t) * t * (((s) + 1) * t + s) + 2) + b
    End If

End Function

Shared Function easeInBounce(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    easeInBounce = c - easeOutBounce(d - t, 0, c, d) + b

End Function

Shared Function easeOutBounce(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    If (t / d) < (1 / 2.75) Then

        t = t / d

        easeOutBounce = c * (7.5625 * t * t) + b

    ElseIf t < (2 / 2.75) Then

        t = t - (1.5 / 2.75)

        easeOutBounce = c * (7.5625 * t * t + 0.75) + b

    ElseIf t < (2.5 / 2.75) Then

        t = t - (2.25 / 2.75)
        easeOutBounce = c * (7.5625 * t * t + 0.9375) + b

    Else

        t = t - (2.625 / 2.75)

        easeOutBounce = c * (7.5625 * t * t + 0.984375) + b

    End If

End Function

Shared Function easeInOutBounce(ByVal t As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double

    If t < d / 2 Then
        easeInOutBounce = easeInBounce(t * 2, 0, c, d) * 0.5 + b
    Else
        easeInOutBounce = easeOutBounce(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b
    End If

End Function

End Class

I appreciate your cooperation!

    
asked by Pablo Fac 21.04.2018 в 05:22
source

0 answers