GithubHelp home page GithubHelp logo

makhaon / jcl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from project-jedi/jcl

4.0 4.0 0.0 80.67 MB

JEDI Code Library

Home Page: http://jcl.delphi-jedi.org

Perl 0.03% Pascal 84.59% PHP 0.08% HTML 0.47% CSS 0.02% Makefile 0.24% TeX 13.41% C++ 0.52% Batchfile 0.04% Shell 0.01% C 0.45% NASL 0.14% SourcePawn 0.01%

jcl's People

Contributors

ahausladen avatar boramis avatar cycocrew avatar ekot1 avatar fabi2607 avatar jfudickar avatar joshkel avatar kalwados avatar lomo74 avatar makhaon avatar markjforte avatar obones avatar outchy avatar rburgstaler avatar rf232 avatar romanyankovsky avatar uschuster avatar vitaliyg2 avatar wormnest avatar

Stargazers

 avatar  avatar  avatar  avatar

jcl's Issues

Request to add 2 small functions in JclGraphUtils unit;

type

.../...

type TColorSwap
private
public
class function ComplementaryColorFromHtmlColor(AHtmlColor: TColor; bSwapRedBlue: Boolean = False): TColor;
class function ComplementaryColor(AColor: TColor): TColor;
class function HighContrastColor(AColor: TColor): TColor;
class function SwappedRedGreenColor(AColor: TColor): TColor;
class function SwappedRedBlueColor(AColor: TColor): TColor;
end;
.../...

implementation

.../...

class function TColorSwap.ComplementaryColorFromHtmlColor(AHtmlColor: TColor; bSwapRedBlue: Boolean = False): TColor;
{$REGION 'Xls: Comments section'}
{
@param bSwapRedBlue: this parameter depends from your material context, and the purpose of this call:

  • from the logic of use: let's say you found and copy a pretty #aabbcc color on a website, i.e. a hexdecimal representation in a string type, and you are looking for its complementary color to highlight TLabels on a TPanel for exemple, in Free Pascal. #aabbcc means that Red='#aa', Green='#bb', and Blue='#cc'. Even before calculating the complementary, it must be known that if you want to copy this color in Free Pascal, as it is, ie $aabbcc to a Canvas.Color property for example, it will not always work (depending on CPU type): indeed, the binary bits are read from right to left. So, the compiled equivalent will \ could have to be Red=$cc, Green=$bb Blue=$cc on your machine.
  • from your CPU: into a file, Motorola writes AColor's RGB in that order ie RGB; but Intel writes it inversed ie BGR.

Trick, to check first, which convention is used:

  • HTML writes the hex code in Motorola format, and the GIMP shows the color hex code in Motorola Format too ==> with such a format, if you take this color code from HTML or from the GIMP, then you'll have to swap red and blue.
  • easy other test: fill some component's Color property, with Color:= $FF ==> if it is red you are on an Intel machine (swap needed, if we use a HTML color's display).
    Otherwise if it is blue you are on a Motorala machine (no swap needed, if we use a HTML color's display).

NB: if you use reference colors like clBlack, clLime, etc., from the LCL to find the complementary color of these, then leave bSwapRedBlue to false: the colors of the components are already natively - with respect to your machine's CPU - correctly managed. Or even better: use ComplementaryColor.
}
{$ENDREGION}

      function SwapRedBlue(AColor: TColor): TColor;
     {$REGION 'Xls: Comments section'}
      { See ComplementaryColorFromHtmlColor explanations. }
     {$ENDREGION}
      begin
      Result:= RGBToColor(Graphics.Blue(AColor), Graphics.Green(AColor), Graphics.Red(AColor))
      end;

begin
if bSwapRedBlue then
SwapRedBlue(AHtmlColor);
Result:= RGBToColor(255 - Graphics.Red(AHtmlColor), 255 - Graphics.Green(AHtmlColor), 255 - Graphics.Blue(AHtmlColor));
end;

class function TColorSwap.ComplementaryColor(AColor: TColor): TColor;
{$REGION 'Xls: Comments section'}
{ most efficient for complementary color. }
{$ENDREGION}
begin
Result := clWhite - ColorToRGB(AColor);
end;

class function TColorSwap.HighContrastColor(AColor: TColor): TColor;
{$REGION 'Xls: Comments section'}
{ The one that returns the color with the most contrast, in the middle of grey or pastel colors. }
{$ENDREGION}
begin
AColor := ColorToRGB(AColor);
if Red(AColor) + Green(AColor) + Blue(AColor) < 3*128 then
Result := clWhite
else
Result := clBlack;
end;

class function TColorSwap.SwappedRedGreenColor(AColor: TColor): TColor;
{$REGION 'Xls: Comments section'}
{ inspired from the "triadic color scheme": if color_base=RGB ==> sequencing triad_1=GBR, triad_2=BRG... }
{$ENDREGION}
begin
AColor := ColorToRGB(AColor);
Result := RGBToColor(Green(AColor), Red(AColor), Blue(AColor));
end;

class function TColorSwap.SwappedRedBlueColor(AColor: TColor): TColor;
{$REGION 'Xls: Comments section'}
{ inspired from the "triadic color scheme": if color_base=RGB ==> sequencing triad_1=GBR, triad_2=BRG... }
{$ENDREGION}
begin
AColor := ColorToRGB(AColor);
Result := RGBToColor(Blue(AColor), Green(AColor), Red(AColor));
end;


Best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.