Skip to content

Maths Library

Person8880 edited this page Nov 30, 2014 · 2 revisions

Overview

The maths library included with Shine extends the math library with extra useful functions.

math.Clamp

math.Clamp( number Value, number Min, number Max )

Returns a number that is clamped between the given min and max values.

math.ClampEx

math.ClampEx( number Value[, number Min, number Max] )

Identical to math.Clamp when all arguments are present. Otherwise, providing only Value returns Value, providing Value and Min performs math.max( Value, Min ) or providing Value and Max performs math.min( Value, Max ).

math.EaseIn

math.EaseIn( number Progress, number Power )

Pass in a progress number between 0 and 1, and a power value and it will return a value that can be used to move an object with acceleration at the start of the movement. This is used in SGUI for control animations.

math.EaseInOut

math.EaseInOut( number Progress, number Power )

Pass in a progress number between 0 and 1, and a power value and it will return a value that can be used to move an object with acceleration at the start and end of the movement. This is used in SGUI for control animations.

math.EaseOut

math.EaseOut( number Progress, number Power )

Pass in a progress number between 0 and 1, and a power value and it will return a value that can be used to move an object with acceleration at the end of the movement. This is used in SGUI for control animations.

math.InRange

math.InRange( number LowerBound, number Value, number UpperBound )

Returns the result of the mathematical expression: LowerBound < Value <= UpperBound.

math.GenerateSequence

math.GenerateSequence( number Length, table Values )

Returns an array that is a sequence of numbers. The possible numbers in the sequence should be given by the Values table. The sequence will not have more than math.ceil( Length / #Values ) of any of the given numbers. The sequence will be different every time the function is called with the same inputs.

For example:

local Sequence = math.GenerateSequence( 5, { 1, 2 } )

PrintTable( Sequence )

--[[
Output (example only, not guaranteed):
> 1 = 1
> 2 = 1
> 3 = 2
> 4 = 2
> 5 = 1
]]

math.Round

math.Round( Number, DecimalPlaces )

Returns the input number rounded to the given number of decimal places.

Clone this wiki locally