{{newin|[[11.3]]|113|type=function}}
Converts a color from 0..255 to 0..1 range.

== Function ==
=== Synopsis ===
<source lang="lua">
r, g, b, a = love.math.colorFromBytes( rb, gb, bb, ab )
</source>
=== Arguments ===
{{param|number|rb|Red color component in 0..255 range.}}
{{param|number|gb|Green color component in 0..255 range.}}
{{param|number|bb|Blue color component in 0..255 range.}}
{{param|number|ab (nil)|Alpha color component in 0..255 range.}}
=== Returns ===
{{param|number|r|Red color component in 0..1 range.}}
{{param|number|g|Green color component in 0..1 range.}}
{{param|number|b|Blue color component in 0..1 range.}}
{{param|number|a (nil)|Alpha color component in 0..1 range or nil if alpha is not specified.}}

== Notes ==
Here's implementation for [[11.2]] and earlier.
<source lang="lua">
function love.math.colorFromBytes(r, g, b, a)
	if type(r) == "table" then
		r, g, b, a = r[1], r[2], r[3], r[4]
	end
	r = clamp01(floor(r + 0.5) / 255)
	g = clamp01(floor(g + 0.5) / 255)
	b = clamp01(floor(b + 0.5) / 255)
	a = a ~= nil and clamp01(floor(a + 0.5) / 255) or nil
	return r, g, b, a
end
</source>
Where <code>clamp01</code> is defined as follows
<source lang="lua">
local function clamp01(x)
	return math.min(math.max(x, 0), 1)
end
</source>

== See Also ==
* [[parent::love.math]]
* [[love.graphics.setColor]]
* [[love.math.colorToBytes]]
[[Category:Functions]]
{{#set:Description=Converts a color from 0..255 to 0..1 range.}}

== Other Languages ==
{{i18n|love.math.colorFromBytes}}