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 566629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:59:53+00:00 2026-05-13T12:59:53+00:00

I’m trying to graphically display a graph of N lines and I’m trying to

  • 0

I’m trying to graphically display a graph of N lines and I’m trying to find a way to dynamically assign distinct colors based on how many lines I have. The values in RGB range from 0 to 1. I can’t use white because the background is white. I found it easy for N < 7:

r=(h&0x4)/4;
g=(h&0x2)/2;
b=h&0x1;

This gives me black, blue, green, cyan, red, magenta, yellow. But after that it will use white and then loop. Does anybody know a good way to assign RGB values for an index? I also have an opacity value to play with.

  • 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. Editorial Team
    Editorial Team
    2026-05-13T12:59:54+00:00Added an answer on May 13, 2026 at 12:59 pm

    My preferred method for doing this is to find n evenly-spaced points along the colour wheel.

    We represent the colour wheel as a range of values between 0 and 360. Thus, the values we will use are 360 / n * 0, 360 / n * 1, …, 360 / n * (n - 1). In doing this, we’ve defined the hue of each of our colours. We can describe each of these colours as Hue-Saturation-Value (HSV) colours by setting saturation to 1 and lightness to 1.

    (A higher saturation means the colour is more “rich”; a lower saturation means the colour is closer to gray. A higher lightness means the colour is “brighter”; a lower lightness means the colour is “darker”.)

    Now, a simple calculation gives us the RGB values of each of these colours.

    http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_HSV_to_RGB

    Note that the equations given can be simplified:

    • p = v * (1 – s) = 1 * (1 – 1) = 1 * 0 = 0
    • q = v * (1 – f * s) = 1 * (1 – f * 1) = 1 – f
    • t = v * (1 – (1 – f) * s) = 1 * (1 – (1 – f) * 1) = 1 – (1 – f) = 1 – 1 + f = f

    Pseudo-code-ish Implementation in Python

    Note: This is intentionally a horribly inefficient implementation. The point of giving this example in Python is essentially so I can give executable pseudocode.

    import math
    
    def uniquecolors(n):
        """Compute a list of distinct colors, each of which is represented as an RGB 3-tuple."""
        hues = []
        # i is in the range 0, 1, ..., n - 1
        for i in range(n):
            hues.append(360.0 / i)
    
        hs = []
        for hue in hues:
            h = math.floor(hue / 60) % 6
            hs.append(h)
    
        fs = []
        for hue in hues:
            f = hue / 60 - math.floor(hue / 60)
            fs.append(f)
    
        rgbcolors = []
        for h, f in zip(hs, fs):
            v = 1
            p = 0
            q = 1 - f
            t = f
            if h == 0:
                color = v, t, p
            elif h == 1:
                color = q, v, p
            elif h == 2:
                color = p, v, t
            elif h == 3:
                color = p, q, v
            elif h == 4:
                color = t, p, v
            elif h == 5:
                color = v, p, q
            rgbcolors.append(color)
    
        return rgbcolors
    

    Concise Implementation in Python

    import math
    
    v = 1.0
    s = 1.0
    p = 0.0
    def rgbcolor(h, f):
        """Convert a color specified by h-value and f-value to an RGB
        three-tuple."""
        # q = 1 - f
        # t = f
        if h == 0:
            return v, f, p
        elif h == 1:
            return 1 - f, v, p
        elif h == 2:
            return p, v, f
        elif h == 3:
            return p, 1 - f, v
        elif h == 4:
            return f, p, v
        elif h == 5:
            return v, p, 1 - f
    
    def uniquecolors(n):
        """Compute a list of distinct colors, ecah of which is
        represented as an RGB three-tuple"""
        hues = (360.0 / n * i for i in range(n))
        hs = (math.floor(hue / 60) % 6 for hue in hues)
        fs = (hue / 60 - math.floor(hue / 60) for hue in hues)
        return [rgbcolor(h, f) for h, f in zip(hs, fs)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.