Added Easing library with its documentation

This commit is contained in:
Fabio
2025-04-27 09:25:16 +02:00
parent 40ddcbee52
commit 56c8b1c6d5
6 changed files with 1075 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
/********************************************************************
* EASING Example, Basic usage *
* ---------------------------------------------------------------- *
* Author : Fabio Falcucci (Allanon) *
* License : Freeware *
* Version : 1.0 *
* Release : - *
* Dependancies : Easing.hws *
* *
* PayPal Support hijoe@tin.it *
* Support me on Patreon! https://www.patreon.com/Allanon71 *
* Bitcoin https://coindrop.to/allanon *
* *
* Github repo (leaving) https://github.com/Allanon71 *
* Gitea repo (updated) https://gitea.it/allanon/HollywoodLibs *
* ---------------------------------------------------------------- *
*/
; 1. Include the Easing library
@INCLUDE "../../+Includes.hws"
@INCLUDE #INC_EASING
; @INCLUDE "Easing.hws"
; 2. Setup a tween for a text string that will cross the screen in 10 seconds
; We need a table to hold the text position
Local textPos = { x = 0, y = 320 }
; Let's start the transition
tween.start(10000, ; 10 seconds = 10*1000 milliseconds
textPos, ; The table where we have our variable we want to smoothly change
{ x = 600 }, ; One or more targets : in this case we want to reach x=640 in 10 seconds
"inoutelastic", ; The name of the easing function we want to use
Function() ; A function to call when the transition ends, here we are using an anonymous function to print a message
NPrint("Transition Ended! Click Left Mouse Button")
WaitLeftMouse()
End
EndFunction
)
; 3. We need a function we will call regurarly to update and render
; the scene, we also need a variable to store the previous execution
; time so we can calculate the delta time.
Local previousTime = 0
Local timer = StartTimer(Nil)
Function renderer()
; Calculate the delta time
Local currentTime = GetTimer(timer)
Local deltaTime = currentTime - previousTime
; Update previousTime variable
previousTime = currentTime
; Clear the screen
Cls()
; Update the tweens
tween.update(deltaTime)
; Render the object
TextOut(textPos.x, textPos.y, "HELLO!")
EndFunction
; 4. Setup a Interval function to update & render the tweens @ 100FPS
; meaning every 10 milliseconds.
Local rendererInterval = SetInterval(Nil, renderer, 10)
; 5. Setup an infinite loop and watch the result
Repeat
WaitEvent()
Forever

View File

@@ -0,0 +1,110 @@
/********************************************************************
* EASING Example, Working with tweens *
* ---------------------------------------------------------------- *
* Author : Fabio Falcucci (Allanon) *
* License : Freeware *
* Version : 1.0 *
* Release : 26/03/2014 *
* Dependancies : Easing.hws *
* *
* PayPal Support hijoe@tin.it *
* Support me on Patreon! https://www.patreon.com/Allanon71 *
* Bitcoin https://coindrop.to/allanon *
* *
* Github repo (leaving) https://github.com/Allanon71 *
* Gitea repo (updated) https://gitea.it/allanon/HollywoodLibs *
* ---------------------------------------------------------------- *
*/
@INCLUDE "../../+Includes.hws"
@INCLUDE #INC_EASING
; @INCLUDE "Easing.hws"
; Setup some variables
Items = {} ; Each item will show a differen easing function
StartE = 0 ; First easing
EndE = 40 ; Last easing
Function UpdateScreen()
; This routine will update the screen, tween functions needs the delta time
; to be updated so the first thing to do is calculate this value.
Local cTime = GetTimer(Timer)
Local dTime = cTime - OldTime
; Updates all active tweens
Tween.Update(dTime)
; Update the background color
Box(0, 0, 640, 480, #BLACK)
; Display the objects, one for each defined tween
For Local i = StartE To EndE
TextOut(Items[i].x, Items[i].y, easing[i], { Color = Items[i].Color })
Next
TextOut(10, 10, "(left click to quit) DT:" .. cTime - OldTime)
OldTime = cTime
Flip()
EndFunction
Timer = StartTimer(Nil) ; Start a timer to track delta times
Renderer = SetInterval(Nil, UpdateScreen, 10) ; Call the UpdateScreen every 10ms
OldTime = GetTimer(Timer) ; Initialize the time for the delta times calc
; To make a cross chain betweens the to callback functions we need
; to define an empty function so that the first one does not reference
; a nil value.
Local fBackard = Function() EndFunction
Function fForward(id)
; Define the forward movement
Local id = id.id
Items[id].x = 0
; Look at the callaback function, we are referencing to fBackward that in this
; exact moment point to the empty function defined above
tween.start(10000+Rnd(5000), Items[id], { x = 560 }, easing[id], fBackward, { id = id })
EndFunction
; But now we are redefining the fBackward function replacing the
; empty one.
Function fBackward(id)
; Callback function used initialize and restart every item
Local id = id.id
; Look at the callback function : it points to fForward so that
; when this transition finishes the loop will be started again
tween.start(10000+Rnd(5000), Items[id], { x = 0 }, easing[id], fForward, { id = id })
EndFunction
; Table with all available easing animations
easing =
{ "linear",
"inquad", "outquad", "inoutquad", "outinquad",
"incubic", "outcubic", "inoutcubic", "outincubic",
"inquart", "outquart", "inoutquart", "outinquart",
"inquint", "outquint", "inoutquint", "outinquint",
"insine", "outsine", "inoutsine", "outinsine",
"inexpo", "outexpo", "inoutexpo", "outinexpo",
"incirc", "outcirc", "inoutcirc", "outincirc",
"inelastic", "outelastic", "inoutelastic", "outinelastic",
"inback", "outback", "inoutback", "outinback",
"inbounce", "outbounce", "inoutbounce", "outinbounce" }
; Initialize the tweens, one for each animation available
For Local i = StartE To EndE
Local b = i
Items[i] = { x = 0, y = 50 + i*8, color = GetRandomColor() }
fForward({ id = i })
Next
BeginDoubleBuffer()
SetFillStyle(#FILLCOLOR)
While Not(IsLeftMouse())
WaitEvent()
Wend