Home >Java >javaTutorial >How Can I Generate a Large Set of Visually Distinct Colors?

How Can I Generate a Large Set of Visually Distinct Colors?

Susan Sarandon
Susan SarandonOriginal
2024-10-31 12:04:31632browse

How Can I Generate a Large Set of Visually Distinct Colors?

Automatically Generating Distinct Colors

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:

  • Color displays for categorical images: Provides a palette of 11 colors distinguishable to viewers with color vision deficiencies.
  • A WEB SERVICE TO PERSONALISE MAP COLOURING: Offers a web service to generate custom color sets.
  • An Algorithm for the Selection of High-Contrast Color Sets: Proposes an algorithm for finding contrasting colors.
  • High-contrast sets of colors: Introduces the first algorithm for this problem.

Converting to RGB:

If colors are not specified in RGB format, you may need to convert them using resources like:

  • http://chem8.org/uch/space-55036-do-blog-id-5333.html
  • https://metacpan.org/pod/Color::Library::Dictionary::NBS_ISCC
  • Color Theory: How to convert Munsell HVC to RGB/HSB/HSL

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn