Love2D APIMathModuleOn this pageMathModule 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: ParameterTypeDescriptionseednumberThe initial seed number to use for this object. Returns: Return TypeDescriptionRandomGeneratorrng — 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: ParameterTypeDescriptionlownumberThe 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 TypeDescriptionRandomGeneratorrng — The new Random Number Generator object. newTransform Type: Function. Description: Creates a new Transform object. Signature: newTransform: function(): Transform Returns: Return TypeDescriptionTransformtransform — 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: ParameterTypeDescriptionxnumberThe 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 TypeDescriptionTransformtransform — 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: ParameterTypeDescriptionvertices{number}The vertices of the control polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}. Returns: Return TypeDescriptionBezierCurvecurve — 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: ParameterTypeDescriptioncoordinatesnumber...The vertices of the control polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}. Returns: Return TypeDescriptionBezierCurvecurve — 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: ParameterTypeDescriptionxnumberThe number used to generate the noise value. Returns: Return TypeDescriptionnumbervalue — 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: ParameterTypeDescriptionxnumberThe 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 TypeDescriptionnumbervalue — 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: ParameterTypeDescriptionxnumberThe 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 TypeDescriptionnumbervalue — 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: ParameterTypeDescriptionxnumberThe 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 TypeDescriptionnumbervalue — 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 TypeDescriptionnumbernumber — 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: ParameterTypeDescriptionuppernumberThe maximum possible value it should return. Returns: Return TypeDescriptionnumberThe 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: ParameterTypeDescriptionlowernumberThe minimum possible value it should return.uppernumberThe maximum possible value it should return. Returns: Return TypeDescriptionnumberThe 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: ParameterTypeDescriptionstandard_deviationnumberStandard deviation of the distribution. (Default: 1.)meannumberThe mean of the distribution. (Default: 0.) Returns: Return TypeDescriptionnumberNormally 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: ParameterTypeDescriptionseednumberThe 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: ParameterTypeDescriptionlownumberThe 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 TypeDescriptionnumberInteger 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: The effect of the state string does not depend on the current operating system. Signature: setRandomState: function(state: string) Parameters: ParameterTypeDescriptionstatestringThe 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: The value of the state string does not depend on the current operating system. Signature: getRandomState: function(): string Returns: Return TypeDescriptionstringThe 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: ParameterTypeDescriptionrednumberRed color component.greennumberGreen color component.bluenumberBlue color component.alphanumberAlpha color component. (Default: nil.) Returns: Return TypeDescriptionnumberrb — 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: ParameterTypeDescriptioncolor{number}Red color component. Returns: Return TypeDescriptionnumberrb — 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: ParameterTypeDescriptionrednumberRed 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 TypeDescriptionnumberr — 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: ParameterTypeDescriptioncolor{number}Red color component in 0..255 range. Returns: Return TypeDescriptionnumberr — 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: ParameterTypeDescriptionrednumberThe 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 TypeDescriptionnumberlr — 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: ParameterTypeDescriptioncolor{number}A table with the red, green, and blue channels of the sRGB color to convert. Returns: Return TypeDescriptionnumberlr — 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: ParameterTypeDescriptionrednumberThe 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 TypeDescriptionnumbercr — 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: ParameterTypeDescriptioncolor{number}A table with the red, green, and blue channels of the linear RGB color to convert. Returns: Return TypeDescriptionnumbercr — 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: ParameterTypeDescriptionvertices{number}The vertices of the polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}. Returns: Return TypeDescriptionbooleanconvex — 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: ParameterTypeDescriptioncoordinatesnumber...The vertices of the polygon as a table in the form of {x1, y1, x2, y2, x3, y3, ...}. Returns: Return TypeDescriptionbooleanconvex — 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: ParameterTypeDescriptionvertices{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: ParameterTypeDescriptioncoordinatesnumber...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: ParameterTypeDescriptioncontainerstringThe type of value to return.formatCompressionFormatThe compression format to use.sourcestringDatalevelintegerThe compression level, from 0 to 9, or -1 for the default level. Returns: Return TypeDescriptionstringThe 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: ParameterTypeDescriptioncontainerstringThe type of value to return.formatCompressionFormatThe compression format to use.sourcestringDatalevelintegerThe compression level, from 0 to 9, or -1 for the default level. Returns: Return TypeDescriptionCompressedDataThe 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: ParameterTypeDescriptioncontainerstringThe type of value to return.compressedCompressedDataThe compressed data to decompress. Returns: Return TypeDescriptionstringThe decompressed data as a string. decompress Type: Function. Description: Deprecated alias of love.data.decompress. Signature: decompress: function(container: string, compressed: CompressedData): ByteData Parameters: ParameterTypeDescriptioncontainerstringThe type of value to return.compressedCompressedDataThe compressed data to decompress. Returns: Return TypeDescriptionByteDataThe decompressed data as a ByteData object.