How to make a color progression out of a color palette
Asked Answered
D

3

6

My goal with this algorithm I'm working on is to output a color progression out of some provided colors. By color progression I mean creating the "fade" effect between two colors (color A, color B) and store every color value ((R,G,B) tuple) in between.

For example, if what is provided is total black A = (0,0,0) and total white B = (255,255,255) the progression resultant would be:

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

So that we get white at first and it progressively turns into black. It is, of course, very easy with white and black (just increase RGB by one each step for 255 times). But what if I want to do this procedure with two arbitrary colors, like A = (180,69,1) and B = (233,153,0)??

IMPORTANT NOTE: If with hexadecimal (or any other kind of color notation) it would be easier to achieve, I could work with that too, just specify which type is (take into account that I'm working on PIL (Python Imaging Library), so if it's compatible with that I'm fine)

Obviously it has to be an as even as possible distribution, the progression must be homogeneous.

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

Thanks in advance.

Devaughn answered 5/5, 2011 at 16:30 Comment(0)
T
2

Convert your RGB coordinates to HSL or HSV and step through them, converting back to RGB along the way.

Tuyettv answered 5/5, 2011 at 16:44 Comment(4)
docs.python.org/library/colorsys.html en.wikipedia.org/wiki/HSL_and_HSVTuyettv
I have a problem. I don't know how to step between HSL nor HSV colors :/Devaughn
How would you step between RGB colors?Tuyettv
I know I can't step through RGB, but could you tell me how to step through HSV or HSL? ThanksDevaughn
E
0

I would just interpolate the RGB values independently. See this thread.

Ewens answered 5/5, 2011 at 17:18 Comment(0)
G
0

My answer to the SO question titled Range values to pseudocolor might be helpful to you because it shows one way to generate a specific color gradient (the common name of what you referred to as a color progression).

Generally you can interpolate between any two colors in any colorspace by computing the difference, or delta value, between the components of each color, and then divide those by the number of intermediate steps desired to get a fractional delta amount per component to apply after each step.

Then, starting from the value of each of the first color's components, the corresponding fractional amount can be added to it over-and-over to determine each intermediate step color. Alternatively, the arithmetic error inherent in that approach can be reduced by instead adding (step_number/total_steps) * fractional_delta to the initial color component values of the starting color.

I believe this is what @Jim Clay is also saying in his answer. If you'd like some sample code, say so in a comment.

Geodetic answered 14/6, 2012 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.