% cd-color.sty
% from http://www.taylorgruppe.de/circdia/
% File created by Stefan Krause -- version 1.1 -- 2023/03/10.
% Supports coloring for circdia.sty.
% Electric colors
\definecolor{cdblack}{rgb}{0.1,0.1,0.1}
\definecolor{cdbrown}{rgb}{0.6,0.4,0.2}
\definecolor{cdred}{rgb}{1,0,0}
\definecolor{cdorange}{rgb}{1,0.55,0}
\definecolor{cdyellow}{rgb}{0.95,0.9,0.05}
\definecolor{cdgreen}{rgb}{0,0.7,0}
\definecolor{cdblue}{rgb}{0.3,0.3,1}
\definecolor{cdpurple}{rgb}{0.65,0,1}
\definecolor{cdgray}{rgb}{0.47,0.5,0.47}
\definecolor{cdwhite}{rgb}{0.9,0.9,0.9}
\definecolor{cdgold}{rgb}{0.831373,0.686275,0.215686}
\definecolor{cdsilver}{rgb}{0.611764,0.580392,0.588235}
\newcommand{\textcolorelec}[2]{%
 \ifthenelse{\equal{#1}{0}}{\textcolor{cdblack}{#2}}{}%
 \ifthenelse{\equal{#1}{1}}{\textcolor{cdbrown}{#2}}{}%
 \ifthenelse{\equal{#1}{2}}{\textcolor{cdred}{#2}}{}%
 \ifthenelse{\equal{#1}{3}}{\textcolor{cdorange}{#2}}{}%
 \ifthenelse{\equal{#1}{4}}{\textcolor{cdyellow}{#2}}{}%
 \ifthenelse{\equal{#1}{5}}{\textcolor{cdgreen}{#2}}{}%
 \ifthenelse{\equal{#1}{6}}{\textcolor{cdblue}{#2}}{}%
 \ifthenelse{\equal{#1}{7}}{\textcolor{cdpurple}{#2}}{}%
 \ifthenelse{\equal{#1}{8}}{\textcolor{cdgray}{#2}}{}%
 \ifthenelse{\equal{#1}{9}}{\textcolor{cdwhite}{#2}}{}%
 \ifthenelse{\equal{#1}{G}}{\textcolor{cdgold}{#2}}{}%
 \ifthenelse{\equal{#1}{S}}{\textcolor{cdsilver}{#2}}{}%
}%
% Coloring of \voltar and \polarity
\newcommand{\coloredpn}[2]{
 \ifthenelse{\equal{#1}{}}{}{
  \let\cdoplusold\cdoplus
  \renewcommand\cdoplus[2]{\textcolor{#1}{\cdoplusold{##1}{##2}}}
  \ifthenelse{\equal{#2}{}}{
   \renewcommand{\cdbigarrowline}[1]{
    \draw (0, 0) -- (-0.5*##1, 0);
    \textcolor{#1}{\draw (-0.5*##1, 0) -- (-##1, 0);}
   }
  }{
   \let\cdbigarrowheadold\cdbigarrowhead
   \renewcommand{\cdbigarrowhead}{\textcolor{#2}{\cdbigarrowheadold}}
   \renewcommand{\cdbigarrowline}[1]{
    \textcolor{#2}{\draw (0, 0) -- (-0.5*##1, 0);}
    \textcolor{#1}{\draw (-0.5*##1, 0) -- (-##1, 0);}
   }
  }
 }
 \ifthenelse{\equal{#2}{}}{}{
  \let\cdominusold\cdominus
  \renewcommand\cdominus[2]{\textcolor{#2}{\cdominusold{##1}{##2}}}
  \ifthenelse{\equal{#1}{}}{
   \let\cdbigarrowheadold\cdbigarrowhead
   \renewcommand{\cdbigarrowhead}{\textcolor{#2}{\cdbigarrowheadold}}
   \renewcommand{\cdbigarrowline}[1]{
    \textcolor{#2}{\draw (0, 0) -- (-0.5*##1, 0);}
    \draw (-0.5*##1, 0) -- (-##1, 0);
   }
  }{}
 }
}
% Color stripes in resistors
\newcommand{\colorstripes}[1]{\expandafter\colorstripessep#1}
\newcommand{\colorstripessep}[4]{
 \ifthenelse{\equal{\cdorient}{H}}{
  \textcolorelec{#1}{\fill (-2.1, -0.94) rectangle (-1.3, 0.94);}
  \textcolorelec{#2}{\fill (-1.1, -0.94) rectangle (-0.3, 0.94);}
  \textcolorelec{#3}{\fill (-0.1, -0.94) rectangle (0.7, 0.94);}
  \textcolorelec{#4}{\fill (1.3, -0.94) rectangle (2.1, 0.94);}
 }{
  \textcolorelec{#1}{\fill (-0.94, -2.1) rectangle (0.94, -1.3);}
  \textcolorelec{#2}{\fill (-0.94, -1.1) rectangle (0.94, -0.3);}
  \textcolorelec{#3}{\fill (-0.94, -0.1) rectangle (0.94, 0.7);}
  \textcolorelec{#4}{\fill (-0.94, 1.3) rectangle (0.94, 2.1);}
 }
}
