/// <summary>
        /// Gets a color for given 0 to 1 ratio (i.e. position in range)
        /// </summary>
        /// <param name="ratio">The ratio - position in range from 0 to 1.</param>
        /// <returns></returns>
        public ColorHSVPoint GetHSVColor(Double ratio)
        {
            if (!IsReady)
            {
                Prepare();
            }


            ColorHSVPoint output = BaseColor.Clone();


            if (gradient.HasFlag(ColorGradientFunction.Hue))
            {
                output.H = Convert.ToInt32(RangeH.GetValueForRangePosition(ratio));
            }

            if (gradient.HasFlag(ColorGradientFunction.Value))
            {
                output.V = Convert.ToSingle(RangeV.GetValueForRangePosition(ratio));
            }

            if (gradient.HasFlag(ColorGradientFunction.Saturation))
            {
                output.S = Convert.ToSingle(RangeS.GetValueForRangePosition(ratio)); // output.S + r.S;
            }

            if (gradient.HasFlag(ColorGradientFunction.Alpha))
            {
                output.A = Convert.ToSingle(RangeA.GetValueForRangePosition(ratio));
            }

            output.DeployValues();
            return(output);
        }
        /// <summary>
        /// Gets the color of the hexadecimal.
        /// </summary>
        /// <param name="ratio">The ratio: from 0 to 1</param>
        /// <param name="withAlpha">if set to <c>true</c> [with alpha].</param>
        /// <returns></returns>
        public String GetHexColor(Double ratio, Boolean withAlpha = true)
        {
            ColorHSVPoint output = GetHSVColor(ratio);

            String hex = output.GetHexColor(withAlpha);

            return(hex);
        }
示例#3
0
        public ColorHSVPoint Clone()
        {
            var output = new ColorHSVPoint();

            output.H = H;
            output.V = V;
            output.S = S;
            output.A = A;
            return(output);
        }
示例#4
0
        /// <summary>
        /// Gets the range version --- values are allowed to be negative
        /// </summary>
        /// <param name="b">The b.</param>
        /// <returns></returns>
        public ColorHSVPoint GetRange(ColorHSVPoint b)
        {
            var output = new ColorHSVPoint();

            output.H = H - b.H;

            output.V = V - b.V;
            output.S = S - b.S;
            output.A = A - b.A;
            return(output);
        }
示例#5
0
        public static ColorHSVPoint operator -(ColorHSVPoint a, ColorHSVPoint b)
        {
            ColorHSVPoint output = new ColorHSVPoint();

            output.H  = a.H - b.H;
            output.S -= a.S;
            output.V -= a.V;
            output.A -= a.A;
            output.DeployValues();
            return(output);
        }
示例#6
0
        public static ColorHSVPoint operator +(ColorHSVPoint a, ColorHSVPoint b)
        {
            ColorHSVPoint output = new ColorHSVPoint();

            output.H  = (a.H + b.H);
            output.S += a.S;
            output.V += a.V;
            output.A += a.A;
            output.DeployValues();
            return(output);
        }
示例#7
0
        /// <summary>
        /// Performs multiplication without <see cref="DeployValues"/> call
        /// </summary>
        /// <param name="b">The b.</param>
        /// <returns></returns>
        public ColorHSVPoint GetRangeMultiplied(Double b)
        {
            ColorHSVPoint output = Clone();

            output.H = Convert.ToInt32(H * b); // % 360;

            output.S = S * (float)b;
            output.V = V * (float)b;
            output.A = A * (float)b;

            return(output);
        }
示例#8
0
        public static ColorHSVPoint operator *(ColorHSVPoint a, Double b)
        {
            ColorHSVPoint output = new ColorHSVPoint();

            output.H = Convert.ToInt32(a.H * b); // % 360;

            output.S = a.S * (float)b;
            output.V = a.V * (float)b;
            output.A = a.A * (float)b;

            output.DeployValues();

            return(output);
        }
        protected void Prepare()
        {
            var pointA = new ColorHSVPoint(HexColorA);
            var pointB = new ColorHSVPoint(HexColorB);

            RangeA.Learn(pointA.A);
            RangeA.Learn(pointB.A);

            RangeS.Learn(pointA.S);
            RangeS.Learn(pointB.S);

            RangeV.Learn(pointA.V);
            RangeV.Learn(pointB.V);

            RangeH.Learn(pointA.H);
            RangeH.Learn(pointB.H);

            BaseColor = pointA;
        }
        public List <ColorHSVPoint> GetColorHSVSteps(Int32 colorSegments, Boolean withAlpha = true)
        {
            if (!IsReady)
            {
                Prepare();
            }

            List <ColorHSVPoint> output = new List <ColorHSVPoint>();

            for (int i = 0; i <= colorSegments; i++)
            {
                Double r = i.GetRatio(colorSegments);

                ColorHSVPoint head = GetHSVColor(r);
                output.Add(head);
            }

            return(output);
        }
        /// <summary>
        /// Gets the hexadecimal color dictionary - where Key is color, Double is upper limit for the color segment
        /// </summary>
        /// <param name="colorSegments">The color segments.</param>
        /// <param name="withAlpha">if set to <c>true</c> [with alpha].</param>
        /// <returns></returns>
        public ColorGradientDictionary GetHexColorDictionary(Int32 colorSegments, Boolean withAlpha = true)
        {
            var output = new ColorGradientDictionary();

            if (colorSegments < 1)
            {
                return(output);
            }
            Double c  = 1.GetRatio(colorSegments);
            Double ci = c;

            //var r = PointRange.GetRangeMultiplied(c);

            //var head = PointA.Clone();

            if (!IsReady)
            {
                Prepare();
            }

            for (int i = 0; i < colorSegments; i++)
            {
                Double r = i.GetRatio(colorSegments);

                ColorHSVPoint head = GetHSVColor(r);

                var ci_hex = head.GetHexColor();
                if (!output.ContainsKey(ci_hex))
                {
                    output.Add(ci_hex, ci);
                }
                ci = ci + c;
            }

            return(output);
        }
        public List <String> GetColorSteps(Int32 colorSegments, Boolean withAlpha = true)
        {
            if (!IsReady)
            {
                Prepare();
            }

            List <String> output = new List <string>();

            for (int i = 0; i <= colorSegments; i++)
            {
                Double r = i.GetRatio(colorSegments);

                ColorHSVPoint head = GetHSVColor(r);

                var ci_hex = head.GetHexColor();
                if (!output.Contains(ci_hex))
                {
                    output.Add(ci_hex);
                }
            }

            return(output);
        }
        /// <summary>
        /// Gets a color for given 0 to 1 ratio (i.e. position in range)
        /// </summary>
        /// <param name="ratio">The ratio - position in range from 0 to 1.</param>
        /// <returns></returns>
        public Color GetColor(Double ratio)
        {
            ColorHSVPoint output = GetHSVColor(ratio);

            return(output.GetColor());
        }