Ejemplo n.º 1
0
        public static List <Colour> getTwoComplementaryColours(Colour colour, double angle)
        {
            HSL hsl = colour.getHSL();

            double hVal = hsl.H + angle;

            hVal = hVal >= 360 ? hVal - 360 : hVal;
            HSL positiveHSL = new HSL()
            {
                H = hVal, S = hsl.S, L = hsl.L
            };

            double hVal1 = hsl.H - angle;

            hVal1 = hVal1 <= 0 ? hVal1 + 360 : hVal1;
            HSL negativeHSL = new HSL()
            {
                H = hVal1, S = hsl.S, L = hsl.L
            };

            Colour c0 = Colour.HslToRgb(positiveHSL);
            Colour c1 = Colour.HslToRgb(negativeHSL);

            return(new List <Colour>()
            {
                c0, c1
            });
        }
        /// <summary>
        /// matches the colour passed as an argument with the closest one contained in the list
        /// </summary>
        /// <param name="colour"></param>
        /// <returns></returns>
        public ColourRangeVo getColorMatch(Colour colour)
        {
            ColourRangeVo col = new ColourRangeVo();

            HSL    hsl      = colour.getHSL();
            double r        = colour.R;
            double g        = colour.G;
            double b        = colour.B;
            double h        = hsl.H;
            double s        = hsl.S;
            double l        = hsl.L;
            double ndf      = 0;
            double distance = 255;

            ColourRangeVo tempColour = null;

            for (int i = 0; i < _colourList.Count; i++)
            {
                if (colour.getIsColourMatch(_colourList[i].colour))
                {
                    col.colour = _colourList[i].colour;
                    col.match  = true;
                    col.name   = _colourList[i].name;
                    return(col);
                }

                double hVal = 0.5 * Math.Pow((double)_colourList[i].hsl.H - (double)h, 2);
                double sVal = 0.5 * Math.Pow((double)(_colourList[i].hsl.S * 100) - (double)(s * 100), 2);
                double lVal = Math.Pow((double)(_colourList[i].hsl.L * 100) - (double)(l * 100), 2);

                ndf = hVal + sVal + lVal;
                ndf = Math.Sqrt(ndf);

                if (ndf < distance)
                {
                    distance   = ndf;
                    tempColour = _colourList[i];
                }
            }

            if (tempColour == null)
            {
                col.colour = new Colour();
                col.match  = false;
                col.name   = "Invalid Color";
                return(col);
            }
            else
            {
                col.colour = tempColour.colour;
                col.match  = true;
                col.name   = tempColour.name;
                return(col);
            }
        }
        /// <summary>
        /// matches the colour passed as an argument with the closest one contained in the list
        /// </summary>
        /// <param name="colour"></param>
        /// <returns></returns>
        public ColourRangeVo getColorMatch( Colour colour )
        {
            ColourRangeVo col = new ColourRangeVo();

            HSL hsl = colour.getHSL();
            double r = colour.R;
            double g = colour.G;
            double b = colour.B;
            double h = hsl.H;
            double s = hsl.S;
            double l = hsl.L;
            double ndf = 0;
            double distance = 255;

            ColourRangeVo tempColour = null;

            for (int i = 0; i < _colourList.Count; i++)
            {
                if (colour.getIsColourMatch(_colourList[i].colour))
                {
                    col.colour = _colourList[i].colour;
                    col.match = true;
                    col.name = _colourList[i].name;
                    return col;
                }

                double hVal = 0.5 * Math.Pow((double)_colourList[i].hsl.H - (double)h, 2);
                double sVal = 0.5 * Math.Pow((double)(_colourList[i].hsl.S*100) - (double)(s*100), 2);
                double lVal = Math.Pow((double)(_colourList[i].hsl.L*100) - (double)(l*100), 2);

                ndf = hVal + sVal + lVal;
                ndf = Math.Sqrt(ndf);

                if (ndf < distance)
                {
                    distance = ndf;
                    tempColour = _colourList[i];
                }
            }

            if (tempColour==null)
            {
                col.colour = new Colour();
                col.match = false;
                col.name = "Invalid Color";
                return col;
            }
            else
            {
                col.colour = tempColour.colour;
                col.match = true;
                col.name = tempColour.name;
                return col;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// http://www.easyrgb.com/index.php?X=WEEL
        /// Monochromatic
        /// Colors from the same family on the wheel. This will include lighter, darker and differently saturated versions of the color.
        /// </summary>
        /// <param name="colour"></param>
        /// <returns></returns>
        public static Colour getMonochromatic(Colour colour, double brightness)
        {
            HSL hsl = colour.getHSL();

            double lVal = hsl.L + brightness;

            lVal = (lVal > 1 ? 1 : (lVal < 0 ? 0 : lVal));
            HSL newHSL = new HSL()
            {
                H = hsl.H, S = hsl.S, L = lVal
            };

            return(Colour.HslToRgb(newHSL));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// http://www.easyrgb.com/index.php?X=WEEL
        /// Complement
        /// This is the color opposite on the color wheel.
        /// H° + 180°
        /// </summary>
        /// <param name="colour"></param>
        /// <returns></returns>
        public static Colour getComplement(Colour colour, double angle)
        {
            HSL hsl = colour.getHSL();

            double hVal = hsl.H + angle;

            hVal = hVal >= 360 ? hVal - 360 : hVal;
            HSL positiveHSL = new HSL()
            {
                H = hVal, S = hsl.S, L = hsl.L
            };

            return(Colour.HslToRgb(positiveHSL));
        }