Exemplo n.º 1
0
        /// <summary>
        /// Changes the intensity.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <param name="factor">The factor.</param>
        /// <returns>A color with the new intensity.</returns>
        public static OxyColor ChangeIntensity(this OxyColor color, double factor)
        {
            var hsv = color.ToHsv();

            hsv[2] *= factor;
            if (hsv[2] > 1.0)
            {
                hsv[2] = 1.0;
            }

            return(OxyColor.FromHsv(hsv));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Changes the intensity.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <param name="factor">The factor.</param>
        /// <returns>A color with the new intensity.</returns>
        public static OxyColor ChangeSaturation(this OxyColor color, double factor)
        {
            var hsv = color.ToHsv();

            hsv[1] *= factor;
            if (hsv[1] > 1.0)
            {
                hsv[1] = 1.0;
            }

            return(OxyColor.FromHsv(hsv));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the complementary color.
        /// </summary>
        /// <param name="color">The color to convert.</param>
        /// <returns>The complementary color.</returns>
        public static OxyColor Complementary(this OxyColor color)
        {
            // http://en.wikipedia.org/wiki/Complementary_Color
            var    hsv    = color.ToHsv();
            double newHue = hsv[0] - 0.5;

            // clamp to [0,1]
            if (newHue < 0)
            {
                newHue += 1.0;
            }

            return(OxyColor.FromHsv(newHue, hsv[1], hsv[2]));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate the difference in hue between two <see cref="OxyColor"/>s.
        /// </summary>
        /// <param name="c1">
        /// The first color.
        /// </param>
        /// <param name="c2">
        /// The second color.
        /// </param>
        /// <returns>
        /// The hue difference.
        /// </returns>
        public static double HueDifference(OxyColor c1, OxyColor c2)
        {
            var    hsv1 = c1.ToHsv();
            var    hsv2 = c2.ToHsv();
            double dh   = hsv1[0] - hsv2[0];

            // clamp to [-0.5,0.5]
            if (dh > 0.5)
            {
                dh -= 1.0;
            }

            if (dh < -0.5)
            {
                dh += 1.0;
            }

            double e = dh * dh;

            return(Math.Sqrt(e));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Calculate the difference in hue between two <see cref="OxyColor" />s.
        /// </summary>
        /// <param name="c1">The first color.</param>
        /// <param name="c2">The second color.</param>
        /// <returns>The hue difference.</returns>
        public static double HueDifference(OxyColor c1, OxyColor c2)
        {
            var hsv1 = c1.ToHsv();
            var hsv2 = c2.ToHsv();
            double dh = hsv1[0] - hsv2[0];

            // clamp to [-0.5,0.5]
            if (dh > 0.5)
            {
                dh -= 1.0;
            }

            if (dh < -0.5)
            {
                dh += 1.0;
            }

            double e = dh * dh;
            return Math.Sqrt(e);
        }