private int GetColorID(Color color) { int colorID; bool keyFound; keyFound = UsedColors.TryGetValue(color.ToArgb(), out colorID); if (!keyFound) { colorID = (++_colorIdCounter); UsedColors.Add(color.ToArgb(), colorID); } return(colorID); }
// ****************************************************************** public Color GetNextColor() { while (true) { double hue = _random.NextDouble() * 360; double saturation; double luminance; // To go quicker and darker for white background // saturation = Math.Sqrt(_random.NextDouble()) ; // luminance = Math.Sqrt(_random.NextDouble()); // To go quicker and lighter for dark background //saturation = Math.Pow(_random.NextDouble(), 2.0); //luminance = Math.Pow(_random.NextDouble(), 2.0); // Less performance but higher compatibility saturation = _random.NextDouble(); luminance = _random.NextDouble(); HSL hsl = new HSL(hue, saturation, luminance); Color c = hsl.ToColor(); if (IsFarEnoughFromExistingColor(c, DistanceMin)) { UsedColors.Add(new ColorRatio(c)); DistanceMin += .02; _badTryCount = 0; return(c); } _badTryCount++; if (_badTryCount > Accuracy) { _badTryCount = 0; DistanceMin -= .002; } } }