Recent

Author Topic: color range  (Read 361 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 307
color range
« on: September 22, 2024, 02:41:48 am »
Code: Pascal  [Select][+][-]
  1. showmessage(IntToStr(label2.Font.Color)); //--> 7632896 a variant of green  
  2.  

What are the values of other green colors around 7632896 , it apears they are not simply in range +100, -100 or something ?
lazarus 3.2-fpc-3.2.2-win32/win64

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: color range
« Reply #1 on: September 22, 2024, 05:14:40 am »
Code: Pascal  [Select][+][-]
  1. showmessage(IntToStr(label2.Font.Color)); //--> 7632896 a variant of green  
  2.  

What are the values of other green colors around 7632896 , it apears they are not simply in range +100, -100 or something ?

They're not necessarily linearly adjacent because TColor is really hex values for the BGR components in the color.

So 7632896 is TColor($747800) or RGBToColor($00, $78, $74).
A shade with slightly more blue is TColor($807800) or RGBToColor($00, $78, $80).

Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 307
Re: color range
« Reply #2 on: September 22, 2024, 07:59:02 am »
Thanks. Will try to figure ...
lazarus 3.2-fpc-3.2.2-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 12459
Re: color range
« Reply #3 on: September 22, 2024, 01:31:22 pm »
What are the values of other green colors around 7632896 , it apears they are not simply in range +100, -100 or something ?
You must tranform the RGB color to the HLS color model (RGBToHLS in unit GraphUtil) and then change the luminance (L) by some amount. The attached project "borrows" the procedure "TintedColor" from FPSpreadsheet to create a palette of similar colors based on this idea.

Code: Pascal  [Select][+][-]
  1. uses
  2.   GraphUtil, Math;
  3.  
  4. {@@ ----------------------------------------------------------------------------
  5.   Excel defines theme colors and applies a "tint" factor (-1...+1) to darken
  6.   or brighten them.
  7.  
  8.   This method "tints" a given color with a factor
  9.  
  10.   The algorithm is described in
  11.   http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.backgroundcolor.aspx
  12.  
  13.   @param    AColor   rgb color to be modified
  14.   @param    tint     Factor (-1...+1) to be used for the operation
  15.   @returns  Modified color
  16. -------------------------------------------------------------------------------}
  17. function TintedColor(AColor: TColor; tint: Double): TColor;
  18. type
  19.   TRGBA = packed record R,G,B,A: byte; end;
  20. const
  21.   HLSMAX = 255;
  22. var
  23.   R, G, B: byte;
  24.   H, L, S: Byte;
  25.   lum: Double;
  26. begin
  27.   if (tint = 0) or (TRGBA(AColor).a <> 0) then begin
  28.     Result := AColor;
  29.     exit;
  30.   end;
  31.  
  32.   with TRGBA(AColor) do
  33.     RGBToHLS(R,G,B, H,L,S);
  34.  
  35.   lum := L;
  36.   if tint < 0 then
  37.     lum := lum * (1.0 + tint)
  38.   else
  39.   if tint > 0 then
  40.     lum := lum * (1.0-tint) + (HLSMAX - HLSMAX * (1.0-tint));
  41.   L := Min(255, round(lum));
  42.  
  43.   with TRGBA(Result) do
  44.   begin
  45.     HLSToRGB(H,L,S, R,G,B);
  46.     A := 0;
  47.   end;
  48. end;  
« Last Edit: September 22, 2024, 01:33:00 pm by wp »

 

TinyPortal © 2005-2018