Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a color progression out of a color palette

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.

like image 293
Daniel Wright Avatar asked May 05 '11 16:05

Daniel Wright


1 Answers

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

like image 174
Ignacio Vazquez-Abrams Avatar answered Sep 20 '22 16:09

Ignacio Vazquez-Abrams