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}

텍스트와 배경이 두 가지 색상으로 분할됨

편집하다:tikzfadingfrompicture백그라운드에서 다른 것이 필요하다는 점을 지적하면 하나만으로 만들 수도 있습니다 .

\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또는 목표가 단 하나의 결과인 경우 완전히 제외됩니다 .

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

관련 정보