Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
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.
 

kalimba

macrumors regular
Jun 10, 2008
102
0
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.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
So you're saying by using that formula, I will get all the colors in order from red to violet in order?
 

kpua

macrumors 6502
Jul 25, 2006
294
0
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.
 

kalimba

macrumors regular
Jun 10, 2008
102
0
So you're saying by using that formula, I will get all the colors in order from red to violet in order?
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.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
@ kpua ok, I will try and figure out hues on my own. Thanks!

@ kalimba - sorry I didn't make myself clear... :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.