Skip to content

Instantly share code, notes, and snippets.

@LukaHorvat
Created November 19, 2013 12:22
Show Gist options
  • Save LukaHorvat/7544570 to your computer and use it in GitHub Desktop.
Save LukaHorvat/7544570 to your computer and use it in GitHub Desktop.
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