Add h,s,v properties to Color3 values

We have a HSV constructor for Color3, but no properties for those values. This means we can’t easily interpolate except by manually tracking the values ourselves. Right now I can’t do

color = Color3.fromHSV(color.h, color.s, color.v - 0.1)

I’d have to calculate the current hsv from rgb (the whole reason fromHSV was created in the first place) to do something like that.

Color3 values should have h,s, and v properties.

2 Likes

It’s already possible, but you need to use the method.

_, _, v = Color3.toHSV(color)

Also, it’s worth mentioning that color:lerp(targetColor) is a thing

1 Like

Oh, oops. Missed toHSV on the wiki. Lerp wouldn’t have necessarily been appropriate if you just wanted to change the value instantly.

That was in response to

Even though we have .toHSV, having .h/.s/.v kind of makes sense because we got the same for r/g/b.
(although we don’t have a fromRGB/toRGB so eh)

A mathematical procedure is used to calculate HSV and therefore they aren’t stored in memory. It’s the same reason that euler angles aren’t stored in memory and instead a rotation matrix is, that’s why you have toEulerAnglesXYZ and fromEulerAnglesXYZ but no AngleX, AngleY and, AngleZ.

They could perform the procedure whenever the color is created, so that HSV is always available for each color object, but that would mean more computations are needed to construct a Color3 object (and more memory), so the overall execution time of code that constructs large amounts of Color3 objects would go up.

They could just calculate it when it’s indexed.

But then people will do things like

h, s, v = color.H, color.S, color.V

Which would require the same calculation to be repeated 3 times which leads to poor coding practise.

I think it would look a little more like this (pretending Color3 was implemented in Lua):

function Color3:__index(i)
    if i=="h" or i=="s" or i=="v" then
        local h, s, v = self:toHSV();
        rawset(self, "h", h);
        rawset(self, "s", s);
        rawset(self, "v", v);
        return rawget(self, i);
    end
end

What I mean to convey is that there’s no reason why it would have to be inefficient.

This is the same scenario as Vector3.unit or Vector3.magnitude.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.