How to make a color rendition from a color palette

My goal with this algorithm I'm working on is to infer a color progression from some of the colors provided. By color progression, I mean creating a fading effect between two colors (color A, color B) and saving each color value ((R, G, B)) between them.

For example, if total black A = (0,0,0) and total white B = (255,255,255) , the result is as follows:

P = ((0,0,0),(1,1,1),(2,2,2), .... ,(253,253,253),(254,254,254),(255,255,255)

So, first we get the white color, and it gradually turns into black. This, of course, is very easy with white and black (just increase RGB by every step 255 times). But what if I want to do this procedure with two arbitrary colors, such as A = (180.69.1) and B = (233.153.0) ??

IMPORTANT NOTE: If it was easier to achieve with hexadecimal (or any other color designation), I could handle this as well, just indicate which type (note that I'm working on PIL (Python Imaging Library), so if it's compatible with this, I'm fine)

Obviously, this should be as a possible distribution, the progression should be uniform.

I need to figure out this algorithm so that I can use it in my Fractal Generator (Mandelbrot Set, google, if you want), so it is important that the progression is as soft as possible, no hiccups.

Thanks in advance.

+4
source share
4 answers

Convert your RGB coordinates to HSL or HSV and go through them, switching to RGB along the way.

+2
source

I would just interpolate the RGB values ​​independently. Watch this stream .

0
source

My answer to a SO question called Range values ​​for a pseudocolor may be useful to you, as it shows one way to generate a specific color gradient (the common name for what you call a color progression).

Typically, you can interpolate between any two colors in any color space, calculating the difference or delta value between the components of each color, and then dividing them by the number of intermediate steps that want to obtain a fractional value of the delta by one component to apply after each step.

Then, starting with the value of each of the first color components, an appropriate fractional amount can be added to it over-and-over to determine each color of the intermediate step. Alternatively, the arithmetic error inherent in this approach can be reduced by adding (step_number/total_steps) * fractional_delta to the initial values ​​of the color components of the initial color.

I believe this is what @Jim Clay also says in his answer. If you need any sample code, let's say so in a comment.

0
source

I recommend the same question as Jim Clay, but I read the top . or see Wikipedia for interpolation .

0
source

All Articles