public ConsolePixel GetClosestPixel(Color c) { // TODO: make rounding configurable? // TODO: method to clear cache? c = c.Round(); int key = c.GetRgbInt(); if (_pixelCache.ContainsKey(key)) return _pixelCache[key]; IReadOnlyList<ConsolePixel> pixels = _pixels; if (c.IsGrayscale()) pixels = _grayscalePixels; var w = pixels .Select(p => new { Pixel = p, Distance = c.DistanceTo(p.Color) }) .OrderBy(x => x.Distance) .ToList(); ConsolePixel pixel = w[0].Pixel; _pixelCache.Add(key, pixel); return pixel; }