ARCed.Core.ColorHandler.HSVtoRGB C# (CSharp) Method

HSVtoRGB() public static method

Converts a HSV color values to an RGB color
public static HSVtoRGB ( HSV hsv ) : ARGB
hsv HSV HSV color to convert
return ARGB
        public static ARGB HSVtoRGB(HSV hsv)
        {
            double r = 0.0d, g = 0.0d, b = 0.0d;
            var h = ((double)hsv.Hue / 255 * 360) % 360;
            var s = (double)hsv.Saturation / 255;
            var v = (double)hsv.Value / 255;

            if (Equals(s, 0.0d))
            {
                r = v;
                g = v;
                b = v;
            }
            else
            {
                var sectorPos = h / 60;
                var sectorNumber = (int)(Math.Floor(sectorPos));
                var fractionalSector = sectorPos - sectorNumber;
                var p = v * (1 - s);
                var q = v * (1 - (s * fractionalSector));
                var t = v * (1 - (s * (1 - fractionalSector)));
                switch (sectorNumber)
                {
                    case 0:
                        r = v;
                        g = t;
                        b = p;
                        break;

                    case 1:
                        r = q;
                        g = v;
                        b = p;
                        break;

                    case 2:
                        r = p;
                        g = v;
                        b = t;
                        break;

                    case 3:
                        r = p;
                        g = q;
                        b = v;
                        break;

                    case 4:
                        r = t;
                        g = p;
                        b = v;
                        break;

                    case 5:
                        r = v;
                        g = p;
                        b = q;
                        break;
                }
            }
            return new ARGB(hsv.Alpha, (int)(r * 255), (int)(g * 255), (int)(b * 255));
        }

Same methods

ColorHandler::HSVtoRGB ( int a, int h, int s, int v ) : ARGB