tags:

views:

127

answers:

3

I'd like design a chart and set the colors from a single shade. Same way as in Excel's

alt text

Is there some sort of a formula or algorithm to generate the next shade of color from a given shade or color?

Cheers !

+6  A: 

Look into the HSV colour space. Using it you can produce different shades or tints starting from a given colour. There is a page with Pascal / Delphi code for conversion between RGB and HSV at efg's Computer Lab.

mghie
+9  A: 

That looks to me like they just took the same hue (basic color) and turned the brightness up and down. That can be done easily enough with a HSL or HSV transformations. Check Wikipedia for HSL and HSV color spaces to get some understanding of the theory involved.

Basic idea: Computers represent color with a mixture of red intensity, green intensity and blue intensity, called RGB, because that's the way the screen displays color. HSL (Hue, Saturation, Lightness) and HSV (Hue, Saturation, Value) are two alternative models for representing color that are more intuitive and closer to the way human beings tend to think about how colors look.

Hue is the basic color, represented (more or less) as an angle on a color wheel. Saturation is a linear value, from 0 (gray) to 255 (bright, vibrant color). And Lightness/Value represent brightness, from 0 (black) to 100 (white).

The algorithms to transform from RGB -> HSL and HSL -> RGB (or HSV instead of HSL) are pretty straightforward. Try transforming your color to HS*, adjusting the brightness, and transforming back. By taking several different brightness values from low to high, and arranging them as wedges in a pie chart, you can duplicate that picture pretty easily.

Mason Wheeler
Thanks Mason, as you suggested, I kept the HS constant and make the L varies. I got the result I wanted. Thanks mghie as well for the link. I used efg's algorithim to convert hsv to rgb.
Roderick
Great answer. Also, check the GraphUtil unit in the VCL: ColorAdjustLuma and other functions.
TOndrej
And ColorRGBToHLS and its inverse in the same unit.
Andreas Rejbrand
+1  A: 

Roderick , the @mghie links are great to start, additionally try out the Colorlib Delphi Library , wich lets you convert between color models as well as HTML color conversion utilities. is very complete, full source code included and freeware ;).

check the demo application , in this image you can see a blue pallete generated using this library.

alt text

RRUZ