Wie funktionieren die Mischmodi von Tikz?

Wie funktionieren die Mischmodi von Tikz?

Kurz gesagt, ich möchte genau das tun, was in einem früherenFrage, aber für alle Farben. Oder zumindest besser verstehen, wie es funktioniert.

Genauer gesagt: Ich möchte die Farbe des Textes automatisch entsprechend der Hintergrundfarbe ändern (was in der zuvor erwähnten Frage geschieht). Die gegebene Antwort, einen Mischmodus zu verwenden, ist für mich ein bisschen „magisch“: Sie funktioniert für Blau und Weiß. Aber ich würde gerne wissen, wie man dasselbe für jedes Farbpaar (sagen wir und ) macht colorA. colorBIch habe die Dokumentation zu Mischmodi gelesen, aber keine Formel oder keinen Algorithmus gefunden, den ich zurückentwickeln könnte, um die „magische“ Antwort für beliebige Farben zu reproduzieren (oder zumindest zu verstehen, wie sie funktioniert).

Hier ist ein MWE:

\documentclass{beamer}
\usepackage{tikz}
\usetheme{Madrid}

\definecolor{colorA}{RGB}{255,0,0} % Red for the example but could be any other color
\definecolor{colorB}{RGB}{0,0,255} % Blue for the example but could be or any other color

% Define colorC and colorD to fit with the blend of colorA and colorB
\colorlet{colorC}{colorA!50!colorB} % 
\colorlet{colorD}{colorB!50!colorA} % or maybe something like R_A + R_B, G_A + G_B, B_A + B_B

\usebackgroundtemplate{
    \begin{tikzpicture}
        \coordinate (A) at (0,0);
        \coordinate (B) at (0,\paperheight);
        \coordinate (C) at (\paperwidth,0);
        \coordinate (D) at (\paperwidth,\paperheight);
        \fill[colorA] (A) -- (C) -- (B) -- cycle;
        \fill[colorB](D) -- (C) -- (B) -- cycle;
    \end{tikzpicture}
}
\begin{document}

\begin{frame}
    \frametitle{Example}
    \pgfsetblendmode{difference}% or another blend mode
    \color{colorC} Could this text appear with colorA on a colorB background and with colorB on colorA background?
\end{frame}

\end{document}

Antwort1

Dies beantwortet die Frage nicht wirklich (ich glaube, dass dies bei beliebigen Farben unmöglich ist), ist aber eine Möglichkeit, das Ergebnis zu erzielen.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings}
\definecolor{colorA}{RGB}{200,0,0}
\definecolor{colorB}{RGB}{0,0,200}

\begin{tikzfadingfrompicture}[name=myfading]
\fill[transparent!0] (-1.5,-1) -- (-1.5,1) -- (1.5,-1) --cycle;
\node[transparent!100] {\Huge\bf Test};
\clip (-1.5,1) -- (1.5,1) -- (1.5,-1) --cycle;
\node[transparent!0] {\Huge\bf Test};
\end{tikzfadingfrompicture}

\begin{tikzfadingfrompicture}[name=myinversefading]
\fill[transparent!0] (-1.5,-1) rectangle (1.5,1);
\fill[transparent!100, path fading=myfading, fit fading=false] (-1.5,-1) rectangle (1.5,1);
\end{tikzfadingfrompicture}

\begin{document}
\begin{tikzpicture}
\fill[colorA, path fading=myfading, fit fading=false] (-1.5,-1) rectangle (1.5,1);
\fill[colorB, path fading=myinversefading, fit fading=false] (-1.5,-1) rectangle (1.5,1);
\end{tikzpicture}
\end{document}

Text und Hintergrund zweifarbig geteilt

Bearbeiten:Kann auch mit nur einem gemacht werden tikzfadingfrompicture, wenn nichts anderes im Hintergrund benötigt wird

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings}
\definecolor{colorA}{RGB}{200,0,0}
\definecolor{colorB}{RGB}{0,0,200}

\begin{tikzfadingfrompicture}[name=myfading]
\fill[transparent!0] (-1.5,-1) -- (-1.5,1) -- (1.5,-1) --cycle;
\node[transparent!100] {\Huge\bf Test};
\clip (-1.5,1) -- (1.5,1) -- (1.5,-1) --cycle;
\node[transparent!0] {\Huge\bf Test};
\end{tikzfadingfrompicture}

\begin{document}
\begin{tikzpicture}
\fill[colorA] (-1.5,-1) rectangle (1.5,1);
\fill[colorB, path fading=myfading, fit fading=false] (-1.5,-1) rectangle (1.5,1);
\end{tikzpicture}
\end{document}

oder ganz ohne tikzfadingfrompicture, wenn das Ziel nur dieses eine Ergebnis ist:

\documentclass[tikz, border=1cm]{standalone}
\definecolor{colorA}{RGB}{200,0,0}
\definecolor{colorB}{RGB}{0,0,200}
\begin{document}
\begin{tikzpicture}
\fill[colorA] (-1.5,-1) -- (1.5,-1) -- (-1.5,1) --cycle;
\node[colorB] {\Huge\bf Test};
\clip (-1.5,1) -- (1.5,1) -- (1.5,-1) --cycle;
\fill[colorB] (-1.5,1) -- (1.5,1) -- (1.5,-1) --cycle;
\node[colorA] {\Huge\bf Test};
\end{tikzpicture}
\end{document}

verwandte Informationen