%
% complexbasis.tex -- template for standalon tikz images
%
% (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
%
\documentclass[tikz]{standalone}
\usepackage{amsmath}
\usepackage{times}
\usepackage{txfonts}
\usepackage{pgfplots}
\usepackage{csvsimple}
\usetikzlibrary{arrows,intersections,math}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\def\skala{1}
\begin{tikzpicture}[>=latex,thick,scale=\skala]

\definecolor{darkgreen}{rgb}{0,0.6,0}

\def\s{0.5}
\def\h{0.02}

\def\rechteck#1#2#3{
	\fill[color=#3!20,rounded corners=2pt]
		({-\s+\h},{(2*(#1)-1)*\s+\h})
		rectangle
		({\s-\h},{(2*(#2)+1)*\s-\h});
	\draw[color=#3,rounded corners=2pt]
		({-\s+\h},{(2*(#1)-1)*\s+\h})
		rectangle
		({\s-\h},{(2*(#2)+1)*\s-\h});
	\foreach \y in {{#1},...,{#2}}{
		\fill[color=#3] (0,{2*\y*\s}) circle[radius=0.05];
	}
}
\def\Rechteck#1#2{
	\draw[rounded corners=3pt]
		({-\s-\h},{(2*(#1)-1)*\s-\h})
		rectangle
		({\s+\h},{(2*(#2)+1)*\s+\h});
}

\def\abbildung#1#2#3#4{
	\fill[color=gray!20]
		({\s},{(2*(#1)+1)*\s})
		--
		({3.5-\s},{-\s})
		--
		({3.5-\s},{(2*(#3)+1)*\s})
		--
		({\s},{(2*(#1)+1)*\s})
		--
		cycle;
	\fill[color=gray!40]
		({\s},{(2*(#1+1)-1)*\s})
		--
		({3.5-\s},{(2*(#3+1)-1)*\s})
		--
		({3.5-\s},{(2*(#4)+1)*\s})
		--
		({\s},{(2*(#2)+1)*\s})
		--
		cycle;
	\draw[<-,color=gray]
		({\s},{(2*(#1+1)-1)*\s})
		--
		({3.5-\s},{(2*(#3+1)-1)*\s});
	\draw[->,color=gray]
		({3.5-\s},{(2*(#4)+1)*\s})
		--
		({\s},{(2*(#2)+1)*\s});
	\draw[<-,color=gray!40]
		({\s},{(2*(#1)+1)*\s})
		--
		({3.5-\s},{-\s});
}

\clip (-5.5,-1.2) rectangle (8.5,11.7);

\begin{scope}[xshift=-7cm]
	\abbildung{6}{7}{10}{11}
\end{scope}

\begin{scope}[xshift=-3.5cm]
	\abbildung{6}{10}{7}{11}
	\rechteck{0}{6}{red}
	\rechteck{7}{10}{darkgreen}
	\rechteck{11}{11}{blue}
	\Rechteck{0}{11}
	\node[color=darkgreen] at ({0},{(9*2-1)*\s}) {$B_{k-2\mathstrut}$};
	\node at (1.75,{9*2*\s}) {$\Delta_{k-1}$};
	\node at (1.75,{-\s}) [above] {$\partial_{k-1\mathstrut}$};
	\draw[decorate,decoration={brace,amplitude=4pt}]
		({-\s-0.1},{-\s}) -- ({-\s-0.1},{(2*10+1)*\s});
	\node at ({-\s-0.17},{10*\s}) [left] {$Z_{k-2\mathstrut}$};
	\node at (0,{-\s}) [below] {$C_{k-2\mathstrut}$};
\end{scope}

\begin{scope}
	\abbildung{2}{7}{5}{10}
	\rechteck{8}{11}{blue}
	\rechteck{3}{7}{darkgreen}
	\rechteck{0}{2}{red}
	\Rechteck{0}{11}
	\node at (0,{-\s}) [below] {$C_{k-1\mathstrut}$};
	\node[color=darkgreen] at ({0},{(5*2-1)*\s}) {$B_{k-1\mathstrut}$};
	\node at (1.75,{6.5*2*\s}) {$\Delta_k$};
	\node at (1.75,{-\s}) [above] {$\partial_{k\mathstrut}$};
	\draw[decorate,decoration={brace,amplitude=4pt}]
		({-\s-0.1},{-\s}) -- ({-\s-0.1},{(2*7+1)*\s});
	\node at ({-\s-0.17},{7*\s}) [left] {$Z_{k-1\mathstrut}$};
\end{scope}

\begin{scope}[xshift=3.5cm]
	\abbildung{3}{5}{5}{7}
	\rechteck{6}{10}{blue}
	\rechteck{4}{5}{darkgreen}
	\rechteck{0}{3}{red}
	\Rechteck{0}{10}
	\node at (0,{-\s}) [below] {$C_{k\mathstrut}$};
	\node[color=darkgreen] at ({-0.25},{9*\s})
		{$B_{k\mathstrut}$};
	\node[color=darkgreen] at (0.24,{2*4*\s}) {$b_1$};
	\node[color=darkgreen] at (0.24,{2*4.5*\s+0.1}) {$\vdots$};
	\node[color=darkgreen] at (0.24,{2*5*\s}) {$b_r$};
	\node[color=red] at (0.24,{2*0*\s}) {$z_1$};
	\node[color=red] at (0.24,{2*1*\s}) {$z_2$};
	\node[color=red] at (0.24,{2*2*\s+0.1}) {$\vdots$};
	\node[color=red] at (0.24,{2*3*\s}) {$z_l$};
	\node[color=blue] at (0.24,{2*6*\s}) {$c_1$};
	\node[color=blue] at (0.24,{2*7*\s}) {$c_2$};
	\node[color=blue] at (0.24,{2*8*\s}) {$c_3$};
	\node[color=blue] at (0.24,{2*9*\s}) {$\vdots$};
	\node[color=blue] at (0.24,{2*10*\s}) {$c_s$};
	\node at (1.75,{5.5*2*\s}) {$\Delta_{k+1}$};
	\node at (1.75,{-\s}) [above] {$\partial_{k+1\mathstrut}$};
	\draw[decorate,decoration={brace,amplitude=4pt}]
		({-\s-0.1},{-\s}) -- ({-\s-0.1},{(2*5+1)*\s});
	\node at ({-\s-0.17},{5*\s}) [left] {$Z_{k\mathstrut}$};
\end{scope}

\begin{scope}[xshift=7cm]
	\abbildung{0}{5}{4}{8}
	\rechteck{5}{7}{blue}
	\rechteck{1}{5}{darkgreen}
	\rechteck{0}{0}{red}
	\Rechteck{0}{7}
	\node at (0,{-\s}) [below] {$C_{k+1\mathstrut}$};
	\node[color=darkgreen] at ({0},{(2.0*2+1)*\s})
		{$B_{k+1\mathstrut}$};
	\draw[decorate,decoration={brace,amplitude=4pt}]
		({-\s-0.1},{-\s}) -- ({-\s-0.1},{(2*5+1)*\s});
	\node at ({-\s-0.17},{5*\s}) [left] {$Z_{k+1\mathstrut}$};
\end{scope}

\end{tikzpicture}
\end{document}

