\RequirePackage{xcolor}

\definecolor{diverging4-1-1}{RGB}{44,123,182}
\definecolor{diverging4-1-2}{RGB}{171,217,233}
\definecolor{diverging4-1-3}{RGB}{253,174,97}
\definecolor{diverging4-1-4}{RGB}{215,25,28}

\definecolor{diverging4-2-1}{RGB}{94,60,153}
\definecolor{diverging4-2-2}{RGB}{178,171,210}
\definecolor{diverging4-2-3}{RGB}{253,184,99}
\definecolor{diverging4-2-4}{RGB}{230,97,1}

\definecolor{sequential4-1}{RGB}{34,94,168}
\definecolor{sequential4-2}{RGB}{65,182,196}
\definecolor{sequential4-3}{RGB}{161,218,180}
\definecolor{sequential4-4}{RGB}{235,235,184}

\definecolor{sequential4-1-1}{RGB}{34,94,168}
\definecolor{sequential4-1-2}{RGB}{65,182,196}
\definecolor{sequential4-1-3}{RGB}{161,218,180}
\definecolor{sequential4-1-4}{RGB}{235,235,184}

\definecolor{qualitative4-1}{RGB}{51,160,44}
\definecolor{qualitative4-2}{RGB}{178,223,138}
\definecolor{qualitative4-3}{RGB}{31,120,180}
\definecolor{qualitative4-4}{RGB}{166,206,227}

% square lattice (width #1, height #2, origin #3, spacing #4)
\def\grid#1#2#3{
  \foreach\i in {0,...,#2}{
    \draw#3++(0,\i)--++(#1,0);
  }
  \foreach\i in {0,...,#1}{
    \draw#3++(\i,0)--++(0,#2);
  }
}
\def\gridcolor#1#2#3#4{
  \foreach\i in {0,...,#2}{
    \draw[color=#4]#3++(0,\i)--++(#1,0);
  }
  \foreach\i in {0,...,#1}{
    \draw[color=#4]#3++(\i,0)--++(0,#2);
  }
}


% 3-staircase (color #1, position #2)
% speedup
\def\staircase#1#2{
  \fill[color=#1]#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
  \draw[color=white]#2++(-0.5,0)--++(3,0);
  \draw[color=white]#2++(-0.5,1)--++(2,0);
  \draw[color=white]#2++(-0.5,2)--++(1,0);
  \draw[color=white]#2++(0,-0.5)--++(0,3);
  \draw[color=white]#2++(1,-0.5)--++(0,2);
  \draw[color=white]#2++(2,-0.5)--++(0,1);
  \draw[color=black, line width=2pt]#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
}
%\def\staircase#1#2{
%  \fill[color=#1]#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
%  \begin{scope}
%    \clip#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
%    \grid44{[color=white]#2++(-1,-1)}
%  \end{scope}
%  \draw[color=black]#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
%}

% 4-staircase (color #1, position #2)
\def\Staircase#1#2{
  \fill[color=#1]#2++(-0.5,-0.5)--++(4,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-4);
  \begin{scope}
    \clip#2++(-0.5,-0.5)--++(4,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-4);
    \grid55{[color=white]#2++(-1,-1)}
  \end{scope}
  \draw[color=black, line width=2pt]#2++(-0.5,-0.5)--++(4,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-4);
}

% 5-staircase (color #1, position #2)
\def\staircaseV#1#2{
  \fill[color=#1]#2++(-0.5,-0.5)--++(5,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-5);
  \begin{scope}
    \clip#2++(-0.5,-0.5)--++(5,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-5);
    \grid55{[color=white]#2++(-1,-1)}
  \end{scope}
  \draw[color=black, line width=2pt]#2++(-0.5,-0.5)--++(5,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-5);
}

% square (color #1, position #2)
\def\square#1#2{
  \fill[color=#1]#2++(-0.5,-0.5)--++(1,0)--++(0,1)--++(-1,0)--++(0,-1);
  \begin{scope}
    \clip#2++(-0.5,-0.5)--++(1,0)--++(0,1)--++(-1,0)--++(0,-1);
    \grid22{[color=white]#2++(-1,-1)}
  \end{scope}
  %\draw[color=black]#2++(-0.5,-0.5)--++(1,0)--++(0,1)--++(-1,0)--++(0,-1);
}

% disk (color #1, position #2)
\def\disk#1#2{
  \fill[color=#1]#2circle(2.5);
  \begin{scope}
    \clip#2circle(2.5);
    \grid66{[color=white]#2++(-3,-3)}
  \end{scope}
  \draw[color=black, line width=2pt]#2circle(2.5);
}

% octagon (color #1, position #2)
\def\octagon#1#2{
  \fill[color=#1]#2++(-1,-2.5)--++(2,0)--++(1.5,1.5)--++(0,2)--++(-1.5,1.5)--++(-2,0)--++(-1.5,-1.5)--++(0,-2)--++(1.5,-1.5);
  \begin{scope}
    \clip#2++(-1,-2.5)--++(2,0)--++(1.5,1.5)--++(0,2)--++(-1.5,1.5)--++(-2,0)--++(-1.5,-1.5)--++(0,-2)--++(1.5,-1.5);
    \grid66{[color=white]#2++(-3,-3)}
  \end{scope}
  \draw[color=black, line width=2pt]#2++(-1,-2.5)--++(2,0)--++(1.5,1.5)--++(0,2)--++(-1.5,1.5)--++(-2,0)--++(-1.5,-1.5)--++(0,-2)--++(1.5,-1.5);
}
