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

  • Home
  • SEARCH
  • 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 128213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:35:59+00:00 2026-05-11T05:35:59+00:00

I wrote the two methods below to automatically select N distinct colors. It works

  • 0

I wrote the two methods below to automatically select N distinct colors. It works by defining a piecewise linear function on the RGB cube. The benefit of this is you can also get a progressive scale if that’s what you want, but when N gets large the colors can start to look similar. I can also imagine evenly subdividing the RGB cube into a lattice and then drawing points. Does anyone know any other methods? I’m ruling out defining a list and then just cycling through it. I should also say I don’t generally care if they clash or don’t look nice, they just have to be visually distinct.

public static List<Color> pick(int num) {     List<Color> colors = new ArrayList<Color>();     if (num < 2)         return colors;     float dx = 1.0f / (float) (num - 1);     for (int i = 0; i < num; i++) {         colors.add(get(i * dx));     }     return colors; }  public static Color get(float x) {     float r = 0.0f;     float g = 0.0f;     float b = 1.0f;     if (x >= 0.0f && x < 0.2f) {         x = x / 0.2f;         r = 0.0f;         g = x;         b = 1.0f;     } else if (x >= 0.2f && x < 0.4f) {         x = (x - 0.2f) / 0.2f;         r = 0.0f;         g = 1.0f;         b = 1.0f - x;     } else if (x >= 0.4f && x < 0.6f) {         x = (x - 0.4f) / 0.2f;         r = x;         g = 1.0f;         b = 0.0f;     } else if (x >= 0.6f && x < 0.8f) {         x = (x - 0.6f) / 0.2f;         r = 1.0f;         g = 1.0f - x;         b = 0.0f;     } else if (x >= 0.8f && x <= 1.0f) {         x = (x - 0.8f) / 0.2f;         r = 1.0f;         g = 0.0f;         b = x;     }     return new Color(r, g, b); } 
  • 1 1 Answer
  • 0 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. 2026-05-11T05:35:59+00:00Added an answer on May 11, 2026 at 5:35 am

    You can use the HSL color model to create your colors.

    If all you want is differing hues (likely), and slight variations on lightness or saturation, you can distribute the hues like so:

    // assumes hue [0, 360), saturation [0, 100), lightness [0, 100)  for(i = 0; i < 360; i += 360 / num_colors) {     HSLColor c;     c.hue = i;     c.saturation = 90 + randf() * 10;     c.lightness = 50 + randf() * 10;      addColor(c); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How is the autocomplete field being initialized? Is it being… May 11, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer There are lots of different ways to accomplish this: Dynamic… May 11, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer Try to use source /home/yourname/bin/Screen/multiUserSettings instead. My guess is that… May 11, 2026 at 5:49 pm

Related Questions

I want to convert function object to function. I wrote this code, but it
I made a class and in one of its methods I needed to calculate
I have found some info on the subject ( like this link) , but
Edit: I apologize everybody. I used the term jagged array when I actually meant

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.