Hello everyone!
I am trying to set the hue values of a color between 0.0f and 1.0f.
However, when 1.0f is reached, it gets set back to 0.0f.
Is a color’s hue clamped between 0.0f and 1.0f, not including 1.0f?
How would I include 1.0f?
This is a demo code that shows the issue:
Color32 color1 = new Color32(255,0,0,255);
float color1_hue = 0.0f;
float color1_saturation = 0.0f;
float color1_value = 0.0f;
void Start () {
Color.RGBToHSV(color1,out color1_hue,out color1_saturation,out color1_value);
Debug.Log("color1_hue: " + color1_hue.ToString());
color1_hue = 0.25f;
color1 = Color.HSVToRGB(color1_hue,color1_saturation,color1_value);
Color.RGBToHSV(color1,out color1_hue,out color1_saturation,out color1_value);
Debug.Log("color1_hue: " + color1_hue.ToString());
color1_hue = 0.5f;
color1 = Color.HSVToRGB(color1_hue,color1_saturation,color1_value);
Color.RGBToHSV(color1,out color1_hue,out color1_saturation,out color1_value);
Debug.Log("color1_hue: " + color1_hue.ToString());
color1_hue = 0.75f;
color1 = Color.HSVToRGB(color1_hue,color1_saturation,color1_value);
Color.RGBToHSV(color1,out color1_hue,out color1_saturation,out color1_value);
Debug.Log("color1_hue: " + color1_hue.ToString());
color1_hue = 1.0f;
color1 = Color.HSVToRGB(color1_hue,color1_saturation,color1_value);
Color.RGBToHSV(color1,out color1_hue,out color1_saturation,out color1_value);
Debug.Log("color1_hue: " + color1_hue.ToString());
color1_hue = 1.01f;
color1 = Color.HSVToRGB(color1_hue,color1_saturation,color1_value);
Color.RGBToHSV(color1,out color1_hue,out color1_saturation,out color1_value);
Debug.Log("color1_hue: " + color1_hue.ToString());
}
When running this code, I get the following messages in the Console:
“color1_hue: 0”
“color1_hue: 0.2503268”
“color1_hue: 0.5”
“color1_hue: 0.7496732”
“color1_hue: 0”
“color1_hue: 0.009803922”
Best wishes,
Shu