/// <summary>
        /// Creates color from HSB color space with random hue and saturation and brighness equal to 1.
        /// </summary>
        /// <returns></returns>
        public static Color CreateColorWithRandomHue()
        {
            double   hue      = random.NextDouble() * 360;
            HsbColor hsbColor = new HsbColor(hue, 1, 1);

            return(hsbColor.ToArgbColor());
        }
        /// <summary>
        /// Creates HSBColor from the ARGB color.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <returns></returns>
        public static HsbColor FromArgbColor(Color color)
        {
            double limit255 = 255;

            double r = color.R / limit255;
            double g = color.G / limit255;
            double b = color.B / limit255;

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

            double len = max - min;

            double brightness = max;             // 0.5 * (max + min);
            double sat;
            double hue;


            if (max == 0 || len == 0)
            {
                sat = hue = 0;
            }
            else
            {
                sat = len / max;
                if (r == max)
                {
                    hue = (g - b) / len;
                }
                else if (g == max)
                {
                    hue = 2 + (b - r) / len;
                }
                else
                {
                    hue = 4 + (r - g) / len;
                }
            }

            hue *= 60;
            if (hue < 0)
            {
                hue += 360;
            }


            HsbColor res = new HsbColor();

            res.hue        = hue;
            res.saturation = sat;
            res.brightness = brightness;
            res.alpha      = color.A / limit255;
            return(res);
        }
        public static Color[] CreateRandomColors(int colorNum)
        {
            double startHue = random.NextDouble() * 360;

            Color[] res     = new Color[colorNum];
            double  hueStep = 360.0 / colorNum;

            for (int i = 0; i < res.Length; i++)
            {
                double hue = startHue + i * hueStep;
                res[i] = new HsbColor(hue, 1, 1).ToArgbColor();
            }

            return(res);
        }
 /// <summary>
 /// Determines whether the specified <see cref="object"/> is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="object"/> to compare with this instance.</param>
 /// <returns>
 ///     <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public override bool Equals(object obj)
 {
     if (obj is HsbColor)
     {
         HsbColor c = (HsbColor)obj;
         return(c.alpha == alpha &&
                c.brightness == brightness &&
                c.hue == hue &&
                c.saturation == saturation);
     }
     else
     {
         return(false);
     }
 }
        public static SolidColorBrush ChangeSaturation(this SolidColorBrush brush, double saturationFactor)
        {
            Color    color    = brush.Color;
            HsbColor hsbColor = HsbColor.FromArgbColor(color);

            hsbColor.Saturation *= saturationFactor;

            if (hsbColor.Saturation > 1.0)
            {
                hsbColor.Saturation = 1.0;
            }

            SolidColorBrush result = new SolidColorBrush(hsbColor.ToArgbColor());

            return(result);
        }
        public static SolidColorBrush ChangeLightness(this SolidColorBrush brush, double lightnessFactor)
        {
            Color    color    = brush.Color;
            HsbColor hsbColor = HsbColor.FromArgbColor(color);

            hsbColor.Brightness *= lightnessFactor;

            if (hsbColor.Brightness > 1.0)
            {
                hsbColor.Brightness = 1.0;
            }

            SolidColorBrush result = new SolidColorBrush(hsbColor.ToArgbColor());

            return(result);
        }
 public static HsbColor ToHsbColor(this Color color)
 {
     return(HsbColor.FromArgbColor(color));
 }