For example, at step s: red = startingRed + ((float)s * stepSizeRed) You can then iterate over the steps, at each one adding another step size and rounding to get the new value for each component. The step sizes for the other components are zero as they don't change. For the red-orange example the step size for the Red component would thus be 1.91 (because you have 86 steps and a total change of ( 0xA2 - 0x00, or 162 in decimal, yielding 162/86=1.91). This is given by the total change in that component divided by the total number of steps. For each component you then work out the step size required for each step in your 'fade'. You use this to get the RGB array of your starting and ending colour (for example, for the red-orange range in your example this would be the RGB breakdown of 0xFF0000 and 0xFFA200). This code gives you the three component colours for a fully-stated colour fullColour: std::array colourRGB To get the RGB components some bit manipulation is necessary. This means using steps that are of as equal size as possible. One way to do what you want is to interpolate each of the component colours (RGB) from their starting to their ending value. find the distance to the start of the closest regionĬase 0: r = 255 g = 0 b = 0 g += x break Ĭase 1: r = 255 g = 255 b = 0 r -= x break Ĭase 2: r = 0 g = 255 b = 0 b += x break Ĭase 3: r = 0 g = 255 b = 255 g -= x break Ĭase 4: r = 0 g = 0 b = 255 r += x break Ĭase 5: r = 255 g = 0 b = 255 b -= x break we want to normalize ratio so that it fits in to 6 regions This can be done with following code: //input: ratio is between 0.0 to 1.0 This produces 256 * 6 colors, we may not want all of those colors, so it has to be normalized. In each pass, one of the red, green, blue components is always 0, the second is 255, and the third is increasing or decreasing between 0 and 255.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |