Skip to main content

MathModule

Description:

  Provides system-independent mathematical functions.

newRandomGenerator

Type: Function.

Description:

  Creates a new RandomGenerator object which is completely independent of other RandomGenerator objects and random functions.

Signature:

newRandomGenerator: function(seed?: number): RandomGenerator

Parameters:

ParameterTypeDescription
seednumberThe initial seed number to use for this object.

Returns:

Return TypeDescription
RandomGeneratorrng — The new Random Number Generator object.

newRandomGenerator

Type: Function.

Description:

  Creates a new RandomGenerator object which is completely independent of other RandomGenerator objects and random functions.

Signature:

newRandomGenerator: function(low: number, high: number): RandomGenerator

Parameters:

ParameterTypeDescription
lownumberThe lower 32 bits of the seed number to use for this object.
highnumberThe higher 32 bits of the seed number to use for this object.

Returns:

Return TypeDescription
RandomGeneratorrng — The new Random Number Generator object.

newTransform

Type: Function.

Description:

  Creates a new Transform object.

Signature:

newTransform: function(): Transform

Returns:

Return TypeDescription
Transformtransform — The new Transform object.

newTransform

Type: Function.

Description:

  Creates a new Transform object.

Signature:

newTransform: function(x: number, y: number, angle?: number, scale_x?: number, scale_y?: number, origin_x?: number, origin_y?: number, shear_x?: number, shear_y?: number): Transform

Parameters:

ParameterTypeDescription
xnumberThe position of the new Transform on the x-axis.
ynumberThe position of the new Transform on the y-axis.
anglenumberThe orientation of the new Transform in radians. (Default: 0.)
scale_xnumberScale factor on the x-axis. (Default: 1.)
scale_ynumberScale factor on the y-axis. (Default: sx.)
origin_xnumberOrigin offset on the x-axis. (Default: 0.)
origin_ynumberOrigin offset on the y-axis. (Default: 0.)
shear_xnumberShearing / skew factor on the x-axis. (Default: 0.)
shear_ynumberShearing / skew factor on the y-axis. (Default: 0.)

Returns:

Return TypeDescription
Transformtransform — The new Transform object.

newBezierCurve

Type: Function.

Description:

  Creates a new BezierCurve object.

-- The number of vertices in the control polygon determines the degree of the curve, e.g. three vertices define a quadratic (degree 2) Bézier curve, four vertices define a cubic (degree 3) Bézier curve, etc.

Signature:

newBezierCurve: function(vertices: {number}): BezierCurve

Parameters:

ParameterTypeDescription
vertices{number}The vertices of the control polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}.

Returns:

Return TypeDescription
BezierCurvecurve — A Bézier curve object.

newBezierCurve

Type: Function.

Description:

  Creates a new BezierCurve object.

-- The number of vertices in the control polygon determines the degree of the curve, e.g. three vertices define a quadratic (degree 2) Bézier curve, four vertices define a cubic (degree 3) Bézier curve, etc.

Signature:

newBezierCurve: function(coordinates: number...): BezierCurve

Parameters:

ParameterTypeDescription
coordinatesnumber...The vertices of the control polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}.

Returns:

Return TypeDescription
BezierCurvecurve — A Bézier curve object.

noise

Type: Function.

Description:

  Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.

-- Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.

-- There are many webpages which discuss Perlin and Simplex noise in detail.

Signature:

noise: function(x: number): number

Parameters:

ParameterTypeDescription
xnumberThe number used to generate the noise value.

Returns:

Return TypeDescription
numbervalue — The noise value in the range of 1.

noise

Type: Function.

Description:

  Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.

-- Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.

-- There are many webpages which discuss Perlin and Simplex noise in detail.

Signature:

noise: function(x: number, y: number): number

Parameters:

ParameterTypeDescription
xnumberThe first value of the 2-dimensional vector used to generate the noise value.
ynumberThe second value of the 2-dimensional vector used to generate the noise value.

Returns:

Return TypeDescription
numbervalue — The noise value in the range of 1.

noise

Type: Function.

Description:

  Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.

-- Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.

-- There are many webpages which discuss Perlin and Simplex noise in detail.

Signature:

noise: function(x: number, y: number, z: number): number

Parameters:

ParameterTypeDescription
xnumberThe first value of the 3-dimensional vector used to generate the noise value.
ynumberThe second value of the 3-dimensional vector used to generate the noise value.
znumberThe third value of the 3-dimensional vector used to generate the noise value.

Returns:

Return TypeDescription
numbervalue — The noise value in the range of 1.

noise

Type: Function.

Description:

  Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.

-- Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.

-- There are many webpages which discuss Perlin and Simplex noise in detail.

Signature:

noise: function(x: number, y: number, z: number, w: number): number

Parameters:

ParameterTypeDescription
xnumberThe first value of the 4-dimensional vector used to generate the noise value.
ynumberThe second value of the 4-dimensional vector used to generate the noise value.
znumberThe third value of the 4-dimensional vector used to generate the noise value.
wnumberThe fourth value of the 4-dimensional vector used to generate the noise value.

Returns:

Return TypeDescription
numbervalue — The noise value in the range of 1.

random

Type: Function.

Description:

  Generates a pseudo-random number in a platform independent manner. The default love.run seeds this function at startup, so you generally don't need to seed it yourself.

Signature:

random: function(): number

Returns:

Return TypeDescription
numbernumber — The pseudo-random number.

random

Type: Function.

Description:

  Generates a pseudo-random number in a platform independent manner. The default love.run seeds this function at startup, so you generally don't need to seed it yourself.

Signature:

random: function(upper: number): number

Parameters:

ParameterTypeDescription
uppernumberThe maximum possible value it should return.

Returns:

Return TypeDescription
numberThe pseudo-random integer number.

random

Type: Function.

Description:

  Generates a pseudo-random number in a platform independent manner. The default love.run seeds this function at startup, so you generally don't need to seed it yourself.

Signature:

random: function(lower: number, upper: number): number

Parameters:

ParameterTypeDescription
lowernumberThe minimum possible value it should return.
uppernumberThe maximum possible value it should return.

Returns:

Return TypeDescription
numberThe pseudo-random integer number.

randomNormal

Type: Function.

Description:

  Get a normally distributed pseudo random number.

Signature:

randomNormal: function(standard_deviation?: number, mean?: number): number

Parameters:

ParameterTypeDescription
standard_deviationnumberStandard deviation of the distribution. (Default: 1.)
meannumberThe mean of the distribution. (Default: 0.)

Returns:

Return TypeDescription
numberNormally distributed random number with variance (stddev)² and the specified mean.

setRandomSeed

Type: Function.

Description:

  Sets the seed of the random number generator using the specified integer number. This is called internally at startup, so you generally don't need to call it yourself.

Signature:

setRandomSeed: function(seed: number)

Parameters:

ParameterTypeDescription
seednumberThe integer number with which you want to seed the randomization. Must be within the range of 2^53 - 1.

setRandomSeed

Type: Function.

Description:

  Sets the seed of the random number generator using the specified integer number. This is called internally at startup, so you generally don't need to call it yourself.

Signature:

setRandomSeed: function(low: number, high: number)

Parameters:

ParameterTypeDescription
lownumberThe lower 32 bits of the seed value. Must be within the range of 2^32 - 1.
highnumberThe higher 32 bits of the seed value. Must be within the range of 2^32 - 1.

getRandomSeed

Type: Function.

Description:

  Gets the seed of the random number generator. The seed is split into two numbers due to Lua's use of doubles for all number values - doubles can't accurately represent integer values above 2^53, but the seed can be an integer value up to 2^64.

Signature:

getRandomSeed: function(): number, number

Returns:

Return TypeDescription
numberInteger number representing the lower 32 bits of the random number generator's 64 bit seed value.
numberInteger number representing the higher 32 bits of the random number generator's 64 bit seed value.

setRandomState

Type: Function.

Description:

  Sets the current state of the random number generator. The value used as an argument for this function is an opaque implementation-dependent string and should only originate from a previous call to love.math.getRandomState. This is different from love.math.setRandomSeed in that setRandomState directly sets the random number generator's current implementation-dependent state, whereas setRandomSeed gives it a new seed value. Overload details:

  1. The effect of the state string does not depend on the current operating system.

Signature:

setRandomState: function(state: string)

Parameters:

ParameterTypeDescription
statestringThe new state of the random number generator, represented as a string. This should originate from a previous call to love.math.getRandomState.

getRandomState

Type: Function.

Description:

  Gets the current state of the random number generator. This returns an opaque implementation-dependent string which is only useful for later use with love.math.setRandomState or RandomGenerator:setState. This is different from love.math.getRandomSeed in that getRandomState gets the random number generator's current state, whereas getRandomSeed gets the previously set seed number. Overload details:

  1. The value of the state string does not depend on the current operating system.

Signature:

getRandomState: function(): string

Returns:

Return TypeDescription
stringThe current state of the random number generator, represented as a string.

colorToBytes

Type: Function.

Description:

  Converts a color from 0..1 to 0..255 range.

Signature:

colorToBytes: function(red: number, green: number, blue: number, alpha?: number): number, number, number, number | nil

Parameters:

ParameterTypeDescription
rednumberRed color component.
greennumberGreen color component.
bluenumberBlue color component.
alphanumberAlpha color component. (Default: nil.)

Returns:

Return TypeDescription
numberrb — Red color component in 0..255 range.
numbergb — Green color component in 0..255 range.
numberbb — Blue color component in 0..255 range.
number | nilab — Alpha color component in 0..255 range or nil if alpha is not specified.

colorToBytes

Type: Function.

Description:

  Converts a color from 0..1 to 0..255 range.

Signature:

colorToBytes: function(color: {number}): number, number, number, number | nil

Parameters:

ParameterTypeDescription
color{number}Red color component.

Returns:

Return TypeDescription
numberrb — Red color component in 0..255 range.
numbergb — Green color component in 0..255 range.
numberbb — Blue color component in 0..255 range.
number | nilab — Alpha color component in 0..255 range or nil if alpha is not specified.

colorFromBytes

Type: Function.

Description:

  Converts a color from 0..255 to 0..1 range.

Signature:

colorFromBytes: function(red: number, green: number, blue: number, alpha?: number): number, number, number, number | nil

Parameters:

ParameterTypeDescription
rednumberRed color component in 0..255 range.
greennumberGreen color component in 0..255 range.
bluenumberBlue color component in 0..255 range.
alphanumberAlpha color component in 0..255 range. (Default: nil.)

Returns:

Return TypeDescription
numberr — Red color component in 0..1 range.
numberg — Green color component in 0..1 range.
numberb — Blue color component in 0..1 range.
number | nila — Alpha color component in 0..1 range or nil if alpha is not specified.

colorFromBytes

Type: Function.

Description:

  Converts a color from 0..255 to 0..1 range.

Signature:

colorFromBytes: function(color: {number}): number, number, number, number | nil

Parameters:

ParameterTypeDescription
color{number}Red color component in 0..255 range.

Returns:

Return TypeDescription
numberr — Red color component in 0..1 range.
numberg — Green color component in 0..1 range.
numberb — Blue color component in 0..1 range.
number | nila — Alpha color component in 0..1 range or nil if alpha is not specified.

gammaToLinear

Type: Function.

Description:

  Converts a color from gamma-space (sRGB) to linear-space (RGB). This is useful when doing gamma-correct rendering and you need to do math in linear RGB in the few cases where LÖVE doesn't handle conversions automatically.

-- Read more about gamma-correct rendering here, here, and here.

-- In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.

Signature:

gammaToLinear: function(red: number, green?: number, blue?: number, alpha?: number): number, number | nil, number | nil, number | nil

Parameters:

ParameterTypeDescription
rednumberThe red channel of the sRGB color to convert.
greennumberThe green channel of the sRGB color to convert.
bluenumberThe blue channel of the sRGB color to convert.
alphanumberThe alpha channel, which is returned unchanged. (Default: nil.)

Returns:

Return TypeDescription
numberlr — The red channel of the converted color in linear RGB space.
number | nillg — The green channel of the converted color in linear RGB space.
number | nillb — The blue channel of the converted color in linear RGB space.
number | nillc — The value of the color channel in linear RGB space.

gammaToLinear

Type: Function.

Description:

  Converts a color from gamma-space (sRGB) to linear-space (RGB). This is useful when doing gamma-correct rendering and you need to do math in linear RGB in the few cases where LÖVE doesn't handle conversions automatically.

-- Read more about gamma-correct rendering here, here, and here.

-- In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.

Signature:

gammaToLinear: function(color: {number}): number, number | nil, number | nil, number | nil

Parameters:

ParameterTypeDescription
color{number}A table with the red, green, and blue channels of the sRGB color to convert.

Returns:

Return TypeDescription
numberlr — The red channel of the converted color in linear RGB space.
number | nillg — The green channel of the converted color in linear RGB space.
number | nillb — The blue channel of the converted color in linear RGB space.
number | nillc — The value of the color channel in linear RGB space.

linearToGamma

Type: Function.

Description:

  Converts a color from linear-space (RGB) to gamma-space (sRGB). This is useful when storing linear RGB color values in an image, because the linear RGB color space has less precision than sRGB for dark colors, which can result in noticeable color banding when drawing.

-- In general, colors chosen based on what they look like on-screen are already in gamma-space and should not be double-converted. Colors calculated using math are often in the linear RGB space.

-- Read more about gamma-correct rendering here, here, and here.

-- In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.

Signature:

linearToGamma: function(red: number, green?: number, blue?: number, alpha?: number): number, number | nil, number | nil, number | nil

Parameters:

ParameterTypeDescription
rednumberThe red channel of the linear RGB color to convert.
greennumberThe green channel of the linear RGB color to convert.
bluenumberThe blue channel of the linear RGB color to convert.
alphanumberThe alpha channel, which is returned unchanged. (Default: nil.)

Returns:

Return TypeDescription
numbercr — The red channel of the converted color in gamma sRGB space.
number | nilcg — The green channel of the converted color in gamma sRGB space.
number | nilcb — The blue channel of the converted color in gamma sRGB space.
number | nilc — The value of the color channel in gamma sRGB space.

linearToGamma

Type: Function.

Description:

  Converts a color from linear-space (RGB) to gamma-space (sRGB). This is useful when storing linear RGB color values in an image, because the linear RGB color space has less precision than sRGB for dark colors, which can result in noticeable color banding when drawing.

-- In general, colors chosen based on what they look like on-screen are already in gamma-space and should not be double-converted. Colors calculated using math are often in the linear RGB space.

-- Read more about gamma-correct rendering here, here, and here.

-- In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.

Signature:

linearToGamma: function(color: {number}): number, number | nil, number | nil, number | nil

Parameters:

ParameterTypeDescription
color{number}A table with the red, green, and blue channels of the linear RGB color to convert.

Returns:

Return TypeDescription
numbercr — The red channel of the converted color in gamma sRGB space.
number | nilcg — The green channel of the converted color in gamma sRGB space.
number | nilcb — The blue channel of the converted color in gamma sRGB space.
number | nilc — The value of the color channel in gamma sRGB space.

isConvex

Type: Function.

Description:

  Checks whether a polygon is convex.

-- PolygonShapes in love.physics, some forms of Meshes, and polygons drawn with love.graphics.polygon must be simple convex polygons.

Signature:

isConvex: function(vertices: {number}): boolean

Parameters:

ParameterTypeDescription
vertices{number}The vertices of the polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}.

Returns:

Return TypeDescription
booleanconvex — Whether the given polygon is convex.

isConvex

Type: Function.

Description:

  Checks whether a polygon is convex.

-- PolygonShapes in love.physics, some forms of Meshes, and polygons drawn with love.graphics.polygon must be simple convex polygons.

Signature:

isConvex: function(coordinates: number...): boolean

Parameters:

ParameterTypeDescription
coordinatesnumber...The vertices of the polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}.

Returns:

Return TypeDescription
booleanconvex — Whether the given polygon is convex.

triangulate

Type: Function.

Description:

  Decomposes a simple convex or concave polygon into triangles.

Signature:

triangulate: function(vertices: {number}): {{number}}

Parameters:

ParameterTypeDescription
vertices{number}Polygon to triangulate. Must not intersect itself.

Returns:

Return TypeDescription
{{number}}triangles — List of triangles the polygon is composed of, in the form of {{x1, y1, x2, y2, x3, y3}, {x1, y1, x2, y2, x3, y3}, ...}.

triangulate

Type: Function.

Description:

  Decomposes a simple convex or concave polygon into triangles.

Signature:

triangulate: function(coordinates: number...): {{number}}

Parameters:

ParameterTypeDescription
coordinatesnumber...Polygon to triangulate. Must not intersect itself.

Returns:

Return TypeDescription
{{number}}triangles — List of triangles the polygon is composed of, in the form of {{x1, y1, x2, y2, x3, y3}, {x1, y1, x2, y2, x3, y3}, ...}.

compress

Type: Function.

Description:

  Deprecated alias of love.data.compress.

Signature:

compress: function(container: string, format: CompressionFormat, source: string | Data, level?: integer): string

Parameters:

ParameterTypeDescription
containerstringThe type of value to return.
formatCompressionFormatThe compression format to use.
sourcestringData
levelintegerThe compression level, from 0 to 9, or -1 for the default level.

Returns:

Return TypeDescription
stringThe compressed data as a string.

compress

Type: Function.

Description:

  Deprecated alias of love.data.compress.

Signature:

compress: function(container: string, format: CompressionFormat, source: string | Data, level?: integer): CompressedData

Parameters:

ParameterTypeDescription
containerstringThe type of value to return.
formatCompressionFormatThe compression format to use.
sourcestringData
levelintegerThe compression level, from 0 to 9, or -1 for the default level.

Returns:

Return TypeDescription
CompressedDataThe compressed data as a CompressedData object.

decompress

Type: Function.

Description:

  Deprecated alias of love.data.decompress.

Signature:

decompress: function(container: string, compressed: CompressedData): string

Parameters:

ParameterTypeDescription
containerstringThe type of value to return.
compressedCompressedDataThe compressed data to decompress.

Returns:

Return TypeDescription
stringThe decompressed data as a string.

decompress

Type: Function.

Description:

  Deprecated alias of love.data.decompress.

Signature:

decompress: function(container: string, compressed: CompressedData): ByteData

Parameters:

ParameterTypeDescription
containerstringThe type of value to return.
compressedCompressedDataThe compressed data to decompress.

Returns:

Return TypeDescription
ByteDataThe decompressed data as a ByteData object.