Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

rgb to hex lua

-- assumes decimal values of r, g and b but can be easily retrofitted
function rgb_to_hex(r, g, b)
    --%02x: 0 means replace " "s with "0"s, 2 is width, x means hex
	return string.format("#%02x%02x%02x", 
		math.floor(r*255),
		math.floor(g*255),
		math.floor(b*255))
end

rgb_to_hex(0.01, 0.3, 0.1)
-- returns #024c19
 
PREVIOUS NEXT
Tagged: #rgb #hex #lua
ADD COMMENT
Topic
Name
9+5 =