Added Easing library with its documentation
This commit is contained in:
110
Examples/Easing/WorkingWithTweens.hws
Normal file
110
Examples/Easing/WorkingWithTweens.hws
Normal 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
|
Reference in New Issue
Block a user