Reputation: 4459
Normally I create colors with red, green, blue. However I want the user to pick colors simply with the scrollwheel, thus cannot let the user specify the three colorchannels.
I have a variable that can increment to 256 * 256 * 256.
However if I use bitshift to get the colorchannels I get sudden "jumps" in the color.
How do I get the colorchannels in a way I have a continuous color palette for the integer?
Upvotes: 0
Views: 181
Reputation: 275966
You have a cube that you want to walk over linearly and continuously.
Fortunately, there is no need for the inverse image to be continuous!
If you look here: http://xkcd.com/195/ you'll see a way to walk over a 2 dimensional space linearly and continuously. Changing this walk to a 3 dimensional one isn't fundamentally tricky.
We have 2x2 cube with 8 locations, encoded as 000 through 111:
000 001
010 011
100 101
110 111
these being the coordinates of the top and bottom slices of the cube.
We walk it in this order:
1 -> 2
|
V
/-- 4 <- 3
|
| 6 -> 7
| ^ |
| | V
\-> 5 8
which results in us exiting the cube at the "far corner".
Now, to increase the size of the cube by a factor of two in each dimension, simply take each of the above 8 corners with the same algorithm.
8 layers deep, and we are walking a 256 x 256 x 256 cube in a continuous manner.
Now, I in practice, this might be a bad idea -- but it might be fun to try. :)
There is a relatively simple pattern to the bit values of the locations in order:
000
001
011
010
110
100
101
111
Ie, 0102101 is the bits that are changed in the coordinate.
Or another way of looking at it, is that the way we walk the dimensions is in a Gray code pattern.
Upvotes: 1
Reputation: 16612
I can't think of an intuitive way to do it, as you've got several different degrees of freedom to play with. If you only wanted a base colour and not an arbitrary RGB value, I'd use HSV and scroll through hue values.
Upvotes: 1