How can I obtain the color of a node?
My code so far:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc} % calculates coordinates
\usetikzlibrary{ backgrounds }
\usetikzlibrary{ graphs, graphs.standard }
\usetikzlibrary{ positioning }
\usetikzlibrary{ intersections }
\usepackage{xparse} %For NewDocumentCommand
\usepackage{xcolor}
\tikzset{ every path/.style = {
line width = 0.5mm
}
}
\tikzset { myPlainVrtxStyle/.style = {
circle, minimum size= 5mm,
draw= #1!55!black!90,
fill = #1,
}
}
\makeatletter
\tikzset { myVSplitPlainVrtxStyle/.style args={#1,#2}{%
circle,
minimum size= 5mm,
draw= #1!55!black!90,
fill = #1,
alias=tmp@name,
postaction={%
insert path={
\pgfextra{%
\pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
{\pgfpointanchor{\pgf@node@name}{east}}%
\pgfmathsetmacro\insiderad{\pgf@x}
\fill[#2] (\pgf@node@name.base) ([yshift=\pgflinewidth]\pgf@node@name.south) arc (-90:90:\insiderad-\pgflinewidth)--cycle;
\draw[#2!55!black!90] (\pgf@node@name.base) ([yshift=\pgflinewidth/2]\pgf@node@name.south) arc (-90:90:\insiderad-\pgflinewidth/2);
}
}
}
}
}
\makeatother
%Predefined: black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink, purple, red, teal, violet, white, yellow.
\NewDocumentCommand{\leftG}{m}{
\def \angleOfExit {10}
\node[myPlainVrtxStyle = blue] (0) at #1 {};
\node[myPlainVrtxStyle = teal] at ($ (0) + (0, -2) $) (1) {};
\node[myPlainVrtxStyle = cyan] at ($ (1) + (-90 + \angleOfExit : 2cm) $) (2) {};
\node[myPlainVrtxStyle = violet] at ($ (1) + (-90 - \angleOfExit : 3.5cm) $) (3) {};
\path[name path = intersectionLine1] (3) -- +(-90 + \angleOfExit : 10cm);
\path[name path = intersectionLine2] (2) -- +(-90 - \angleOfExit : 10cm);
\path[name intersections = {of = intersectionLine1 and intersectionLine2}];
\node[myPlainVrtxStyle = olive] at (intersection-1) (4) {};
\graph[ use existing nodes ]{
0 -- 1 -- {2, 3} -- 4;
};
}
\NewDocumentCommand{\rightG}{m}{
\def \angleOfExit {10}
\node[myPlainVrtxStyle = lime] (0) at #1 {};
\node[myPlainVrtxStyle = orange] at ($ (0) + (2cm, 0) $) (1) {};
\node[myPlainVrtxStyle = brown] at ($ (1) + (-\angleOfExit : 2cm) $) (2) {};
\node[myPlainVrtxStyle = black] at ($ (1) + (\angleOfExit : 3.5cm) $) (3) {};
\graph[ use existing nodes ]{
0 -- 1 -- {2, 3}
};
}
\begin{document}
\begin{tikzpicture}
\begin{scope}[ name prefix = LG- ]
\leftG{(0,0)};
\end{scope}
\path let \p1 = ($(LG-0) - (LG-4)$),
\p2 = (LG-2),
in
node (crossPosition) at ($ (\x2 + 1.5cm, -\y1/2) $) {\Huge$\times$};
\begin{scope}[ name prefix = RG- ]
\rightG{($ (crossPosition) + (1.5cm, 0) $)}
\end{scope}
\path let \p1 = (crossPosition),
\p2 = (RG-3),
in
node (eqPosition) at ($ (\x2 + 1.5cm, \y1) $) {\Huge$=$};
\foreach \lv in {0, ..., 4}{ %For each v in the lG
\path let \p1 = (LG-\lv),
\p2 = (eqPosition),
in
coordinate (copyRGLeft\lv) at ( \x2 + 1.5cm + \x1, \y1);
\begin{scope}[ name prefix = CP-\lv ]
\rightG{ (copyRGLeft\lv) };
\end{scope}
}
\foreach \rv in {0, ..., 3} { %For each v in the rG
\graph[ use existing nodes ]{
(CP-0\rv) -- (CP-1\rv) -- { (CP-2\rv), (CP-3\rv) } -- (CP-4\rv);
};
}
% Changing the colors
\begin{pgfonlayer}{main}
\node[ myVSplitPlainVrtxStyle = {blue, lime} ] at (CP-00) {}; %TODO
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
I think if I can obtain the color of the nodes based on their ID the "split coloring" that I need to do later becomes much simpler. Is this possible?
In short, I am investigating the possibility of defining getColor in the following code:
\begin{pgfonlayer}{main}
\foreach \lv in {0, ..., 4}
\foreach \rv in {0, ..., 3}
\node[ myVSplitPlainVrtxStyle = { getColor{LG-\lv}, getColor{RG-\rv} } ] at (CP-\lv\rv) {};
\end{pgfonlayer}
Any improvements or idea in any aspect is welcomed.
Edit: After the answer of @Black Mild I have modified the question to eliminate any ambiguity.




