Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 284187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:26:13+00:00 2026-05-12T05:26:13+00:00

I am looking for an algorithm that will generate a series of colors so

  • 0

I am looking for an algorithm that will generate a series of colors so that the colors will be as widely distributed as possible (so they won’t easily be mixed up).

I have a series of objects that have IDs that count up from 1. I would like to represent each of these with a different, aesthetically pleasing, color that won’t get easily confused with its neighbors. The colors should not necessarily be random though. I would like to get the same color each time I input the same ID.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:26:13+00:00Added an answer on May 12, 2026 at 5:26 am

    Does the number of possible elements have a reasonable low bound? One quick and easy solution is to just store an array of color values using the ID of the item. That assumes that you have a relatively low amount of colors, and you’re certain that you won’t go above a certain number of items, however.

    If you want to generate colors rather than use a list, one trick to make them have a consistent and decent look is to generate them using HSB. Pre-define a brightness and saturation, then base the hue value off some function of the ID (this can be a variety of things depending on how many IDs you plan to have, but multiplying the ID by some amount (and modding when it exceeds 255!) is a good rough approach. With this approach the colors will all “align” in terms of saturation and brightness but they’ll each have a distinct color.

    I’m a bit bored at work, so I whipped together a fast solution:

    class HsbColor
    {
        public int Hue { get; set; }
        public int Saturation { get; set; }
        public int Brightness { get; set; }
    
        public Color ToRGB
        {
            // left as exercise to the reader...
        }
    }
    
    public class Item
    {
    
    
        public int Id { get; set; }
        private static const byte EXPECTED_MAX = 15;
        private static int HUE_FACTOR = 255 / EXPECTED_MAX;
    
        public HsbColor Color 
        {
           get {
    
             var color = new HsbColor() { Saturation = 175, Brightness = 175 };
    
             color.Hue = (Id * HUE_FACTOR) % 255;
    
             return color;
           }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for an algorithm which someone has access to that will compute the
I am looking for an algorithm that will solve my problem in the most
I'm looking for an algorithm that will evenly distribute 1 to many items into
I am looking for an algorithm that will take numbers or words and find
I am looking for an efficient algorithm that will look at a four channel
I am looking for an algorithm that will automatically arrange all the nodes in
I'm looking for a full text search algorithm that will allow to find similar
I am looking for an algorithm that when given a text will cut it
I am looking for protocol/algorithm that will allow me to use a shared secret
I am looking for an algorithm that will allow me to visually separate any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.