Available since LÖVE 11.3
This function is not supported in earlier versions.
Converts a color from 0..1 to 0..255 range.
rb, gb, bb, ab = love.math.colorToBytes( r, g, b, a )
number rnumber gnumber bnumber a (nil)number rbnumber gbnumber bbnumber ab (nil)Here's implementation for 11.2 and earlier.
function love.math.colorToBytes(r, g, b, a) if type(r) == "table" then r, g, b, a = r[1], r[2], r[3], r[4] end r = floor(clamp01(r) * 255 + 0.5) g = floor(clamp01(g) * 255 + 0.5) b = floor(clamp01(b) * 255 + 0.5) a = a ~= nil and floor(clamp01(a) * 255 + 0.5) or nil return r, g, b, a end
Where clamp01 is defined as follows
local function clamp01(x) return math.min(math.max(x, 0), 1) end
© 2006–2020 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.math.colorToBytes