Configurar una macro para colorear nodos en tikz

Configurar una macro para colorear nodos en tikz

Tengo el siguiente código

\documentclass[a0paper,landscape]{article}
\usepackage{tikz}
\usepackage{geometry}
\usetikzlibrary{arrows,patterns,shapes,positioning}
\geometry{margin = .5in}


\begin{document}
    \centering
    \begin{tikzpicture}[
        roundnode/.style = {circle,very thick,draw=blue!70,fill=blue!5,minimum size=7mm},
        cloudnode/.style = {cloud,cloud puffs=10, cloud puff arc=60,draw=cyan!70,fill=cyan!5,minimum width = 5mm,minimum height= 3mm}, 
        rectnode/.style = {rectangle,draw = green!60,fill=green!5,minimum size = 7mm},
    ]
    % Nodes
    \node[roundnode] (titulo) at (0,0) {Eletricidade};
    \node[rectnode,draw=yellow!70,fill=yellow!10] (carga) at (0, -3) {Cargas Elétricas};
    \node[rectnode,draw=red!70,fill=red!5,below left= of carga] (positivas) {Positivas};
    \node[rectnode,draw=blue!70,fill=blue!10,below right= of carga] (negativas) {Negativas};
    
    % Lines
    \begin{scope}[>=stealth,thick]
    \draw[->] (titulo) -- (carga) node [pos=.5,right] {Estuda os fenômenos relacionados a};
    \draw (carga) -- (0,-4)  node [below= 4mm]{Que podem ser} ;
    \draw[->](0,-4) -- (negativas);
    \draw[->](0,-4) -- (positivas);
    \end{scope}
    \end{tikzpicture}
\end{document}

y deseo crear una macro para sustituir draw=[colorname]!70,fill=[colorname]!10donde colorname es cualquier color del paquete xcolor, o al menos los colores nativos de LaTeX. Esta macro debe tomar el nombre del color como parámetro (argumento, idk). De esa manera, puedo colorear el nodo llamando a algo como:

\node[rectnode,nodecolor=blue,{other options}] at ({coordinate}) {Anything}

¿Pueden ayudarme chicos?

Respuesta1

Puede pasar argumentos a estilos y también establecer valores predeterminados. entonces puedes hacer

 rectnode/.style = {rectangle,draw = #1!60,fill=#1!5,minimum size = 7mm},
 rectnode/.default = green

Aquí #1se representa el argumento pasado al estilo. Para usar el color verde predeterminado en un nodo, simplemente haga

\node[rectnode] ...

pero si quieres un color diferente hazlo por ejemplo

\node[rectnode=blue] ...

en cambio. Código completo:

\documentclass{article}
\usepackage{tikz}
\usepackage{geometry}
\usetikzlibrary{arrows,patterns,shapes,positioning}
\geometry{margin = .5in}


\begin{document}
    \centering
    \begin{tikzpicture}[
        roundnode/.style = {circle,very thick,draw=blue!70,fill=blue!5,minimum size=7mm},
        cloudnode/.style = {cloud,cloud puffs=10, cloud puff arc=60,draw=cyan!70,fill=cyan!5,minimum width = 5mm,minimum height= 3mm}, 
        rectnode/.style = {rectangle,draw = #1!60,fill=#1!5,minimum size = 7mm},
        rectnode/.default = green
    ]
    % Nodes
    \node[roundnode] (titulo) at (0,0) {Eletricidade};
    \node[rectnode=yellow] (carga) at (0, -3) {Cargas Elétricas};
    \node[rectnode=red,below left= of carga] (positivas) {Positivas};
    \node[rectnode=blue,below right= of carga] (negativas) {Negativas};
    
    % Lines
    \begin{scope}[>=stealth,thick]
    \draw[->] (titulo) -- (carga) node [pos=.5,right] {Estuda os fenômenos relacionados a};
    \draw (carga) -- (0,-4)  node [below= 4mm]{Que podem ser} ;
    \draw[->](0,-4) -- (negativas);
    \draw[->](0,-4) -- (positivas);
    \end{scope}
    \end{tikzpicture}
\end{document}

información relacionada