When generating a large number of colors, finding means to ensure they are visually different can be challenging. Exploring existing approaches is essential.
Uniform Subdivision of RGB Cube:
This method divides the RGB cube into discrete sections and selects colors from those areas. It can produce a progressive scale, but for large numbers, colors may appear similar.
Using Predefined Lists:
Color lists such as Boynton's or Kelly's provide preselected colors with high contrast, eliminating the need for algorithms.
Algorithm-Based Methods:
Various algorithms have been developed to select distinct colors. These include:
Converting to RGB:
If colors are not specified in RGB format, you may need to convert them using resources like:
Code Examples:
C# code for Boynton's optimized list:
public static readonly List<Color> _boyntonOptimized = new List<Color> { Color.FromArgb(0, 0, 255), //Blue Color.FromArgb(255, 0, 0), //Red Color.FromArgb(0, 255, 0), //Green Color.FromArgb(255, 255, 0), //Yellow Color.FromArgb(255, 0, 255), //Magenta Color.FromArgb(255, 128, 128), //Pink Color.FromArgb(128, 128, 128), //Gray Color.FromArgb(128, 0, 0), //Brown Color.FromArgb(255, 128, 0), //Orange };
JavaFX code for Kelly's colors:
private static final Color[] KELLY_COLORS = { Color.web("0xFFB300"), // Vivid Yellow Color.web("0x803E75"), // Strong Purple Color.web("0xFF6800"), // Vivid Orange Color.web("0xA6BDD7"), // Very Light Blue Color.web("0xC10020"), // Vivid Red Color.web("0xCEA262"), // Grayish Yellow Color.web("0x817066"), // Medium Gray Color.web("0x007D34"), // Vivid Green Color.web("0xF6768E"), // Strong Purplish Pink Color.web("0x00538A"), // Strong Blue Color.web("0xFF7A5C"), // Strong Yellowish Pink Color.web("0x53377A"), // Strong Violet Color.web("0xFF8E00"), // Vivid Orange Yellow Color.web("0xB32851"), // Strong Purplish Red Color.web("0xF4C800"), // Vivid Greenish Yellow Color.web("0x7F180D"), // Strong Reddish Brown Color.web("0x93AA00"), // Vivid Yellowish Green Color.web("0x593315"), // Deep Yellowish Brown Color.web("0xF13A13"), // Vivid Reddish Orange Color.web("0x232C16"), // Dark Olive Green };
The above is the detailed content of How Can I Generate a Large Set of Visually Distinct Colors?. For more information, please follow other related articles on the PHP Chinese website!