Tikz ブレンドモードはどのように機能しますか?

Tikz ブレンドモードはどのように機能しますか?

つまり、私は以前の質問、ただし、どの色でも。または、少なくともそれがどのように機能するかをよりよく理解してください。

より正確に言うと、背景色に応じてテキストの色を自動的に変更したいと思います (これは前述の質問で行われています)。ブレンド モードを使用した回答は、私にとってはちょっと「魔法」のようです。青と白では機能します。しかし、任意の色のペア (たとえば、colorAcolorB) で同じことをする方法を知りたいです。ブレンド モードに関するドキュメントを読みましたが、リバース エンジニアリングして任意の色に対する「魔法の」回答を再現できる (または少なくともそれがどのように機能するかを理解できる) 数式やアルゴリズムは見つかりませんでした。

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}

答え1

これは質問に対する本当の答えではありません (特定の色では不可能だと思います) が、結果を達成する方法です。

\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}

テキストと背景を2色に分割

編集:tikzfadingfrompictureバックグラウンドで他に何も必要ない場合は、1つだけで作成することもできます。

\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}

tikzfadingfrompictureまたは、目標が次の 1 つの結果だけである場合は、まったく必要ありません。

\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}

関連情報