Lighten colors programmatically with Delphi
Many people understand that computers store colors as RGB values and that a value like 770000 represents a dark shade of red. However, RGB values are hard to manipulate in a meaningful way (like brightening a color). That is where the HSL color space comes in handy. In the HSL color space, colors are represented by there Hue, Saturation, and Luminance. The image below shows the full range of Saturation (horizontal axis) and Luminance (vertical axis) when the Hue is fixed at an arbitrary blue value.Once you understand how saturation and luminance affect a hue, you can manipulate these values to produce colors that work well together. For example, the background of the interior boxes in the simple counters shown below were created by adjusting the luminance of the outer box.
The following code was used to do brighten the main color. The functions ColorHLSToRGB and ColorRGBToHSL are defined in the unit GraphUtil.
function Brighten(AColor: TColor): TColor; var H, S, L: Word; begin ColorRGBToHLS(AColor, H, L, S); Result := ColorHLSToRGB(H, 225, S); end;
Warning: this code assumes AColor will have a low luminance value.