Created
November 19, 2013 12:22
-
-
Save LukaHorvat/7544570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Vector4 HSVToRGB(float hue, float saturation, float value, float alpha) | |
{ | |
Func<float, float> helper = (x) => | |
{ | |
float lowerBound = value * (1 - saturation); | |
float delta = value - lowerBound; | |
while (x < 0) x += 360; | |
x = x % 360; | |
return lowerBound + (float)((Math.Floor(x / 180) * value) + Math.Floor(((Math.Floor(x / 60) % 3) / 2)) * (x % 60) * (delta / 60F) * Math.Pow(-1, Math.Floor(x / 180))); | |
}; | |
return new Vector4(helper(hue - 120), helper(360 - hue), helper(hue), alpha); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment