コード例 #1
0
ファイル: HSV.cs プロジェクト: hafewa/ColorPicker
        public static HSVColor FromRGB(RGBColor rgb)
        {
            HSVColor hsv = new HSVColor();

            float max = (float)Math.Max(rgb.r, Math.Max(rgb.g, rgb.b));
            float min = (float)Math.Min(rgb.r, Math.Min(rgb.g, rgb.b));

            hsv.value = max;

            float delta = max - min;

            if (max > float.Epsilon)
            {
                hsv.sat = delta / max;
            }
            else
            {
                // r = g = b = 0
                hsv.sat = 0;
                hsv.hue = float.NaN; // Undefined
                return(hsv);
            }

            if (rgb.r == max)
            {
                hsv.hue = (rgb.g - rgb.b) / delta;    // Between yellow and magenta
            }
            else if (rgb.g == max)
            {
                hsv.hue = 2 + (rgb.b - rgb.r) / delta; // Between cyan and yellow
            }
            else
            {
                hsv.hue = 4 + (rgb.r - rgb.g) / delta; // Between magenta and cyan
            }
            hsv.hue *= 60.0f;                          // degrees
            if (hsv.hue < 0)
            {
                hsv.hue += 360;
            }

            return(hsv);
        }
コード例 #2
0
ファイル: RGB.cs プロジェクト: hafewa/ColorPicker
 public static RGBColor Interpolate(RGBColor c1, RGBColor c2, float value)
 {
     return((c1 * (1.0f - value)) + (c2 * value));
 }