/// <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; } }
public bool Equals(Colour p) { if ((object)p == null) { return false; } return (R == p.R) && (G == p.G) && (B == p.B) && (A == p.A); }
public static string getHex(Colour colour) { return colour.R.ToString("X2") + colour.G.ToString("X2") + colour.B.ToString("X2"); }
/// <summary> /// http://www.easyrgb.com/index.php?X=WEEL /// Analogous /// Uses the colors of the same color temperature near each other on the wheel. /// H° +/- 120° /// </summary> /// <param name="colour"></param> /// <returns></returns> public static List <Colour> getAnalogousComplementaries(Colour colour) { return(getTwoComplementaryColours(colour, 30)); }
/// <summary> /// http://www.easyrgb.com/index.php?X=WEEL /// Triadic /// This is the typical configuration of three colors that are equally spaced from each other on the color wheel. /// H° +/- 120° /// </summary> /// <param name="colour"></param> /// <returns></returns> public static List <Colour> getTriadicComplementaries(Colour colour) { return(getTwoComplementaryColours(colour, 120)); }
/// <summary> /// http://www.easyrgb.com/index.php?X=WEEL /// Split complements /// This color scheme combines the two colors on either side of a color’s complement. /// H° +/- 150° /// </summary> /// <param name="colour"></param> /// <returns></returns> public static List <Colour> getSplitComplementaries(Colour colour) { return(getTwoComplementaryColours(colour, 150)); }
public static string getHex(Colour colour) { return(colour.R.ToString("X2") + colour.G.ToString("X2") + colour.B.ToString("X2")); }