I'm creating a custom beamer theme and defined a command to set the colors used in the presentation like that: \definecolor{primarycolor}{HTML}{9C27B0}
(purple btw).
Let's say primarycolor
is my background color of a frame.
Now, I want to be able to calculate the brightness/luminance of a given color to determine a fitting color for the text (either black or white). In the case of purple, white would be a readable text-color.
I would do it like that (pseudo-code):
luminance := 0.2126 * Red + 0.7152 * Green + 0.0722 * Blue
textcolor := luminance < 128 ? black : white
How do I get the RGB values of a color and then determine the "contrast-color" (black or white)?
\definecolor{mycolor}{RGB}{0,32,96}
[interval [0,255]] or\definecolor{mycolor}{rgb}{0.2, 0.7, 0.7}
[interval [0,1]] help in combination with\selectcolormodel{gray}
(converts color to black-and-white) . Needs\usepackage{xcolor}
.