NSColor help

Discussion in 'Mac Programming' started by liptonlover, Jul 29, 2008.

  1. liptonlover macrumors 6502a

    Joined:
    Mar 13, 2008
    #1
    Is there any way to organize all possible colors of an NSColor into a "rainbow", so that to go through the colors requires just one number instead of rg and b?
    So instead of
    color 255,0,0
    I could do 1
    for instance.
    I'm thinking maybe if I do some array thing... but I don't know where to even begin.
     
  2. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #2
    Counting from 0 to 16,777,215 will give you all possible RGB values (where R, G & B are integer values). Consider that a unique number is yielded from following formula:

    number = (R * 65536) + (G * 256) + B

    Given this formula, you should be able to determine how to extract the color values from your counter.
     
  3. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #3
    So you're saying by using that formula, I will get all the colors in order from red to violet in order?
     
  4. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #4
    If you want something that looks somewhat like an actual rainbow, don't do the above. You can take advantage of the properties of the hue wheel to do this.

    NSColors can be created with this method: +colorWithCalibratedHue:saturation:brightness:alpha:

    A hue of 0.0 or 1.0 is red (since it's a wheel), and the values in the middle are the different hues of the rainbow. So, if you vary the hue from 0.0 to somewhere short of 1.0, you will get colors from red to violet.
     
  5. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #5
    No, that's not what I'm saying, because that's not what was originally asked for. If you need "all possible colors of an NSColor" as originally requested, look for the solution in the formula I've posted.
     
  6. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #6
    @ kpua ok, I will try and figure out hues on my own. Thanks!

    @ kalimba - sorry I didn't make myself clear... :(
     

Share This Page