Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local color3 = {} -- more human readable and simpler way than guessing hex
- function color3.getHexFromRGB(rgb)
- local hexadecimal = "0x"
- for i, value in pairs(rgb) do
- local hex = ''
- while value > 0 do
- local index = math.fmod(value, 16) + 1
- value = math.floor(value / 16)
- hex = string.sub("0123456789ABCDEF", index, index) .. hex
- end
- if (string.len(hex) == 0) then
- hex = "00"
- elseif (string.len(hex) == 1) then
- hex = "0" .. hex
- end
- hexadecimal = hexadecimal .. hex
- end
- return tonumber(hexadecimal)
- end
- function color3.getRGBFromHSV(hsv)
- local r, g, b
- local h, s, v = hsv[1], hsv[2], hsv[3]
- local i = math.floor(h * 6)
- local f = h * 6 - i
- local p = v * (1 - s)
- local q = v * (1 - f * s)
- local t = v * (1 - (1 - f) * s)
- i = i % 6
- if i == 0 then r, g, b = v, t, p
- elseif i == 1 then r, g, b = q, v, p
- elseif i == 2 then r, g, b = p, v, t
- elseif i == 3 then r, g, b = p, q, v
- elseif i == 4 then r, g, b = t, p, v
- elseif i == 5 then r, g, b = v, p, q
- end
- return color3.fromRGB(math.floor(r * 255), math.floor(g * 255), math.floor(b * 255))
- end
- function color3.new(redPercentile, greenPercentile, bluePercentile)
- return color3.getHexFromRGB({ redPercentile * 255, greenPercentile * 255, bluePercentile * 255 })
- end
- function color3.fromHSV(hue, saturation, value)
- return color3.getRGBFromHSV({ hue, saturation, value })
- end
- function color3.fromRGB(red, green, blue)
- return color3.getHexFromRGB({ red, green, blue })
- end
- return color3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement