public double distance(AbstractColor destinationColor) { CIELab a = this.toCIELab(); CIELab b = destinationColor.toCIELab(); return(Math.Sqrt(Math.Pow(a.l - b.l, 2) + Math.Pow(a.a - b.a, 2) + Math.Pow(a.b - b.b, 2))); }
public AbstractColor match(List <AbstractColor> palette) { double distance = double.PositiveInfinity; AbstractColor closest = null; for (int i = 0; i < palette.Count; i++) { double cdistance = this.distance(palette[i]); if (distance == double.PositiveInfinity || cdistance < distance) { distance = cdistance; closest = palette[i]; } } return(closest[this.toSelf]); }
public List <AbstractColor> range(AbstractColor destinationColor, int steps, bool includeSelf) { RGB a = this.toRGB(); RGB b = destinationColor.toRGB(); List <AbstractColor> colors = new List <AbstractColor>(); steps--; double nr, ng, nb; for (int n = 1; n < steps; n++) { nr = Math.Floor((double)a.r + (n * (b.r - a.r) / steps)); ng = Math.Floor((double)a.g + (n * (b.g - a.g) / steps)); nb = Math.Floor((double)a.b + (n * (b.b - a.b) / steps)); colors.Add(new RGB(Convert.ToInt32(nr), Convert.ToInt32(ng), Convert.ToInt32(nb))[this.toSelf]); } if (includeSelf) { colors.Insert(0, this); colors.Add(destinationColor[this.toSelf]); } return(colors); }
public double distance(AbstractColor destinationColor) { CIELab a = this.toCIELab(); CIELab b = destinationColor.toCIELab(); return Math.Sqrt(Math.Pow(a.l - b.l, 2) + Math.Pow(a.a - b.a, 2) + Math.Pow(a.b - b.b, 2)); }
public List<AbstractColor> range(AbstractColor destinationColor, int steps, bool includeSelf) { RGB a = this.toRGB(); RGB b = destinationColor.toRGB(); List<AbstractColor> colors = new List<AbstractColor>(); steps--; double nr, ng, nb; for (int n = 1; n < steps; n++) { nr = Math.Floor((double)a.r + (n * (b.r - a.r) / steps)); ng = Math.Floor((double)a.g + (n * (b.g - a.g) / steps)); nb = Math.Floor((double)a.b + (n * (b.b - a.b) / steps)); colors.Add(new RGB(Convert.ToInt32(nr), Convert.ToInt32(ng), Convert.ToInt32(nb))[this.toSelf]); } if (includeSelf) { colors.Insert(0, this); colors.Add(destinationColor[this.toSelf]); } return colors; }