\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pictures}[2019/09/30]

\RequirePackage{xcolor}
\RequirePackage{tikz,tkz-euclide}



\newcommand{\Square}[2]{\draw[xshift=#1 cm,yshift=#2 cm] (0,0) -- (0,1) -- (1,1) -- (1,0) -- (0,0);}
\newcommand{\ColourSquare}[3]{\draw[xshift=#1 cm,yshift=#2 cm, fill=#3] (0,0) -- (0,1) -- (1,1) -- (1,0) -- (0,0);}
\newcommand{\redSquare}[2]{\draw [fill=red] (#1,#2) rectangle (#1+1,#2+1);}
\newcommand{\blueSquare}[2]{\draw [fill=blue] (#1,#2) rectangle (#1+1,#2+1);}





%*****************************************************
%****************** PlanePartitions ******************
%*****************************************************

% colour Code: 1 - with colours, 2 - in grey, 3 - white


\newcommand{\RightBoundaryColour}[4]{
\begin{scope}[xshift= 1cm*cos(30)*(#1+#2) , yshift=1cm*#3+1cm*sin(30)*(#2-#1)]
\draw [fill=#4] (0,0) -- ({1*cos(30)},{1*sin(30)}) -- ({1*cos(30)},{-1*sin(30)}) -- (0,-1) -- (0,0);
\end{scope}
}
\newcommand{\LeftBoundaryColour}[4]{
\begin{scope}[xshift= 1cm*cos(30)*(#1+#2) , yshift=1cm*#3+1cm*sin(30)*(#2-#1)]
\draw (0,0)[fill=#4] -- ({-1*cos(30)},{1*sin(30)}) -- ({-1*cos(30)},{-1*sin(30)}) -- (0,-1) -- (0,0);
\end{scope}
}
\newcommand{\TopBoundaryColour}[4]{
\begin{scope}[xshift= 1cm*cos(30)*(#1+#2) , yshift=1cm*#3+1cm*sin(30)*(#2-#1)]
\draw (0,0)[fill=#4] -- ({1*cos(30)},{1*sin(30)}) -- (0,1) -- ({-1*cos(30)},{1*sin(30)}) -- (0,0);
\end{scope}
}

\newcommand{\ColourBox}[4]{
\RightBoundaryColour{(#1-1)}{(1-#2)}{(#3-1)}{#4}
\LeftBoundaryColour{(#1-1)}{(1-#2)}{(#3-1)}{#4}
\TopBoundaryColour{(#1-1)}{(1-#2)}{(#3-1)}{#4}
}




\newcommand{\RightBoundary}[4]{
\ifnum #4 =1
	\RightBoundaryColour{#1}{#2}{#3}{green!80!black}
\else \ifnum #4=2
	\RightBoundaryColour{#1}{#2}{#3}{darkgray}
\else
	\RightBoundaryColour{#1}{#2}{#3}{white}
	\fi
\fi
}
\newcommand{\LeftBoundary}[4]{
\ifnum #4 =1
	\LeftBoundaryColour{#1}{#2}{#3}{blue}
\else \ifnum #4 = 2
	\LeftBoundaryColour{#1}{#2}{#3}{lightgray}
\else
	\LeftBoundaryColour{#1}{#2}{#3}{white}
	\fi
\fi
}
\newcommand{\TopBoundary}[4]{
\ifnum #4 =1
	\TopBoundaryColour{#1}{#2}{#3}{red}
\else \ifnum #4=2
	\TopBoundaryColour{#1}{#2}{#3}{white}
\else
	\TopBoundaryColour{#1}{#2}{#3}{white}
	\fi
\fi
}



%The following command creates Plane partitions. As input serves a rectangular array of non-negative intergers (zeros must be listed as well)
	\newcounter{x}
	\newcounter{y}
	\newcounter{z}
	\newcounter{help}

\newcommand{\PlanePartitionColour}[2]{
	\foreach \m [count=\y] in {#1}{		 								%\m = row, \y = number of the row
		\foreach \z [count=\x] in \m{									%\z = entry in the row, \x the position of the entry
			\setcounter{x}{\x}											%remembers the position of the current entry
			\ifnum \z > 0												% if the entry is positive
				\TopBoundary{\x}{-\y}{\z}{#2}								%draw its top
			\fi
			
			\ifnum \x > 1												%if we are not regarding the first entry of the row
				\ifnum \z < \thez										% and if the current entry is less than the previous			
					\setcounter{help}{\z}
					\addtocounter{help}{1}								%has to be done this way since an update (30.10.2019)
					\foreach \zz in {\thehelp,...,\thez}{					
						\RightBoundary{(\x -1)}{(-\y)}{\zz}{#2}				%draw the correct amount of right sides of the boxes in
					}														% the previous position.
				\fi
			\fi
			\ifnum \y > 1											%if we are at least in the second row
				\foreach \mm [count=\yy] in {#1}{					%\mm = another row and \yy is its number
				\ifnum \yy = \they									%if \mm is the row before \m							
				\foreach \zz [count=\xx] in \mm{					%let \zz be the entry in \mm and \xx its position
				\ifnum \xx = \x										%if the positions \xx and \x coincide
				\ifnum \zz > \z										% and the entry \zz is larger than \z
					\setcounter{help}{\zz}									%has to be done like this since the update
					\addtocounter{help}{-1}	
					\foreach \zzz in {\z,...,\thehelp}{
						\LeftBoundary{(\x -1)}{(1-\yy)}{\zzz}{#2}		% draw the correct amount of left sides for the boxes "\zz"
					}
				\fi
				\fi
				}
				\fi
				}
			\fi		
			\setcounter{z}{\z}										%remembers the previous entry	
		}										%done with all entries in row \m
		\ifnum \thez >0												%if the last entry is larger than 0
			\foreach \z in {1,...,\thez}{
				\RightBoundary{\thex}{-\y}{\z}{#2}						%draw the appropriate number of left sides of these boxes
			}
		\fi
		\setcounter{y}{\y}
	}											%done with row \m
	
	
	\foreach \mm [count=\yy] in {#1}{								%regards the left sides of the boxes in the last row
	\ifnum \yy = \they
	\foreach \zz [count=\xx] in \mm{
	\ifnum \zz >0
		\foreach \zzz in {1,...,\zz}{
			\LeftBoundary{(\xx -1)}{(1-\yy)}{(\zzz-1)}{#2}			%draw the appropriate number of left sides of the boxes
		}
	\fi
	}
	\fi
	}
	
}

%\newcommand{\PPColour}[2]{
%	\foreach \m [count=\y] in {#1}{
%		\foreach \z [count=\x] in \m{
%			\setcounter{x}{\x}
%			\ifnum \z > 0
%				\TopBoundary{\x}{-\y}{\z}{#2}
%			\fi
%			\ifnum \x > 1
%				\ifnum \z < \value{z}
%					\foreach \zz in {(\z+1),...,\value{z}}{
%						\RightBoundary{(\x -1)}{(-\y)}{\zz}{#2}
%					}
%				\fi	
%			\fi
%			\ifnum \y > 1
%				\foreach \mm [count=\yy] in {#1}{
%				\ifnum \yy = \value{y}
%				\foreach \zz [count=\xx] in \mm{
%				\ifnum \xx = \x
%				\ifnum \zz > \z
%					\foreach \zzz in {\z,...,(\zz-1)}{
%						\LeftBoundary{(\x -1)}{(1-\yy)}{\zzz}{#2}
%					}
%				\fi
%				\fi
%				}
%				\fi
%				}
%			\fi
%			\setcounter{z}{\z}
%		}
%		\ifnum \value{z} >0
%			\foreach \z in {1,...,\value{z}}{
%				\RightBoundary{\value{x}}{-\y}{\z}{#2}
%			}
%		\fi
%		\setcounter{y}{\y}
%	}
%	\foreach \mm [count=\yy] in {#1}{
%	\ifnum \yy = \value{y}
%	\foreach \zz [count=\xx] in \mm{
%	\ifnum \zz >0
%		\foreach \zzz in {1,...,(\zz)}{
%			\LeftBoundary{(\xx -1)}{(1-\yy)}{(\zzz-1)}{#2}
%		}
%	\fi
%	}
%	\fi
%	}
%}


%\newcommand{\PP}[1]{\PPColour{#1}{1}}
%\newcommand{\PPGray}[1]{\PPColour{#1}{2}}
%\newcommand{\PPWhite}[1]{\PPColour{#1}{3}}

\newcommand{\PlanePartition}[1]{\PlanePartitionColour{#1}{1}}
\newcommand{\PlanePartitionGray}[1]{\PlanePartitionColour{#1}{2}}
\newcommand{\PlanePartitionWhite}[1]{\PlanePartitionColour{#1}{3}}

\newcommand{\Tableaux}[1]{
	\foreach \a [count=\y] in #1{
		\foreach \x in {1,...,\a}{
			\Square{\x}{\y}
		}
	}
}

\newcommand{\ColourTableaux}[2]{
	\foreach \a [count=\y] in #1{
		\foreach \x in {1,...,\a}{
			\ColourSquare{\x}{\y}{#2}
		}
	}
}

