Transition_EaseInElastic2

Syntax

Value.d = Transition_EaseInElastic2(t.d, b.d, c.d, d.d, easeInRatio.d=0.2, amplitude.d=10, wobbleAmount.d=3)

Description

Calculates an intermediate value using a custom elastic effect that combines an initial ease-in phase followed by a decaying wobble or bounce phase. This provides a different feel compared to the standard elastic functions.

Parameters

t.d
The current elapsed time of the animation in milliseconds.

b.d
The starting value of the property being animated.

c.d
The total change in value (target value - starting value).

d.d
The total duration of the animation in milliseconds.

easeInRatio.d (optional)
The proportion (0.0 to 1.0) of the total duration `d` dedicated to the initial ease-in phase. Default is 0.2 (20%).

amplitude.d (optional)
Controls the initial intensity or height of the wobble phase. Default is 10.

wobbleAmount.d (optional)
Controls the frequency or number of wobbles during the second phase. Higher values mean more wobbles. Default is 3.

Return Value

Returns the interpolated value (Double) at the current time `t` according to this custom ease-in/wobble curve.

Remarks

This function offers more control over the elastic effect by separating the ease-in part from the wobble part.

Example

IncludeFile "ProGUI_PB.pbi"

Structure MyAnimData
  TargetValue.d
  StartValue.d
  x.d
EndStructure

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData.MyAnimData)
  
    DrawClear(RGB(200, 200, 200), 1) ; Grey background

    ; Draw a box whose X position is animated
    DrawBox(*UserData\x, (*EventData\height / 2) - 25, 50, 50, RGB(0, 0, 255))
    
EndProcedure

Procedure AnimateHandler(Window, EventType, *EventData.PG_EventAnimate, *UserData.MyAnimData)
  
  Select *EventData\state
  
    Case #PG_Event_Animate_Start
      Debug "Animation started."
      
    Case #PG_Event_Animate_Update
      ; Calculate intermediate value using the ease-in-elastic2 transition
      *UserData\x = Transition_EaseInElastic2(*EventData\currentTime, *UserData\StartValue, *UserData\TargetValue - *UserData\StartValue, *EventData\duration, 0.4, 15, 5) ; Longer ease-in, higher amplitude, more wobbles
      WindowRedraw(Window)
      
    Case #PG_Event_Animate_End
      Debug "Animation ended"
      ; Ensure final value is set exactly
      *UserData\x = *UserData\TargetValue
      WindowRedraw(Window)
      ; Optional: Restart or clean up
      ; FreeStructure(*UserData) 
  EndSelect
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 300, 200, "Transition_EaseInElastic2 Example")

If MyWindow
    
  ; Setup data for animation
  *AnimData.MyAnimData = AllocateStructure(MyAnimData)
  *AnimData\StartValue = 10 
  *AnimData\TargetValue = 200
    
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler(), *AnimData)
  AddEventHandler(MyWindow, #PG_Event_Animate, @AnimateHandler(), *AnimData) 

  ; Start a 2-second animation
  AnimID = StartAnimation(MyWindow, #PG_Any, 2000)

  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
  Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
  
  StopAnimation(MyWindow, AnimID) 
  FreeStructure(*AnimData)
  
EndIf 

StopProGUI()

See Also

Transition_EaseOutElastic2, Transition_EaseInElastic, StartAnimation

Supported OS

Windows, Linux