Interpolation

The function TB.Interpolate() is able to fill a table with a range of values so that you can easily precalculate value variations. It uses the Easing library so that you can make use of any easing function available.

Here is the example coming with the library stored in the TB.TEST_Interpolate() function. If you want to run this code in a new script remember to include the tables library.

  NPrint("Creating a linear value range from 1 To 50 in 50 items")
  Local table = {}
  TB.Interpolate(table, 0, 49, 1, 50, "linear")
  
  For i = 0 To 49 Do NPrint(PadNum(i, 2) .. " : " .. table[i])
  
  NPrint("\nLeft mouse to CONTINUE...")
  WaitLeftMouse()
 
  Cls
  Locate(0, 0)
  NPrint("Creating an InSine value range from 5 To 10 in 50 items")
  Local table = {}
  TB.Interpolate(table, 0, 49, 5, 10, "insine")
  
  For i = 0 To 49 Do NPrint(PadNum(i, 2) .. " : " .. table[i])
  
  NPrint("\nLeft mouse to CONTINUE...")
  WaitLeftMouse()

  Cls
  Locate(0, 0)
  NPrint("Creating an OutElastic value range from 5 To 7 in 30 items")
  Local table = {}
  TB.Interpolate(table, 0, 29, 5, 7, "outelastic")
  
  For i = 0 To 29 Do NPrint(PadNum(i, 2) .. " : " .. table[i])
  
  NPrint("\nLeft mouse to QUIT.")
  WaitLeftMouse()

EndFunction

In the above script you can see how easy is to precalculate values and store them into a table, you just need to provide a destination table, where all the values will be saved, the first and last index positions to use, the starting and ending values and the easing function to use.

For a list of all easing functions available have a look here.

hollywoodlibs/tables/testinterpolation.txt · Ultima modifica: 2016/10/18 10:40 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0