Was saving colors, and since I had to reduce them to one number, instead if a vector3/color3, for some reason it converted it into HSV instead of staying as RGB, and I’m just looking for a way in which to convert HSV into RGB, without having to manually do it which is what most of the things I saw said to do.
So whats the best way to do it without having to do a lot of math?
function hsvToRgb(h, s, v)
local r, g, b
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(r * 255, g * 255, b * 255)
end
local Color = Color3.fromHSV(0.5155, 0.337255, 1)
local New = hsvToRgb(Color:ToHSV())
print(New)
Do Color3.fromHSV(h, s, v) where h, s, and v are in the range [0, 1]. You can get the R G and B components from the R G and B properties of the returned Color3. These will also be in the [0, 1] range.
local color = Color3.fromHSV(.5,.5,.5) -- or any random HSV color
-- multiply the components by 255 and get the nearest number
local r,g,b = math.floor((color.R*255)+0.5),math.floor((color.G*255)+0.5),math.floor((color.B*255)+0.5)
print(r,g,b) -- voila!