箱型平面区画の周期的着色

箱型平面区画の周期的着色

私は以下のコードを使用しています。これは異なる色のレイヤーを作成します。3 つの軸の各レイヤーで同時に機能するように装飾を施すのに問題があります。助けてください。3 つの色 a、b、c を使用して、位置 (a、b、c) のボックスを色 a+b+c mod 3 で色付けしたいと考えています。

コード

% Plane partition
% Author: Jang Soo Kim
\documentclass{standalone}
\usepackage[danish]{babel}
\usepackage{ifthenx}
\usepackage{verbatim}
\usepackage{tikz}

% Three counters
\newcounter{x}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\newcommand{\xaxis}{210}
\newcommand{\yaxis}{-30}
\newcommand{\zaxis}{90}
% The top side of a cube
\newcommand{\topside}[3]{%
  \fill[fill=cubecolor, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
}
% The left side of a cube
\newcommand{\leftside}[3]{%
  \fill[fill=cubecolor, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
}
% The right side of a cube
\newcommand{\rightside}[3]{%
  \fill[fill=cubecolor, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (-30:1) --(0,-1)--(0,0);
}
% The cube 
\newcommand{\cube}[3]{%
  \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}

    % Definition cubecolors
\newcommand*\cubecolors[1]{%
  \ifcase#1\relax
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{blue}%
  \or\colorlet{cubecolor}{red}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{blue}%
  \or\colorlet{cubecolor}{red}%

  \else
    \colorlet{cubecolor}{white}%
  \fi
}

% Definition of \planepartition
\newcommand\planepartition[1]{
 \setcounter{x}{-1}
  \foreach \a in {#1} {
    \addtocounter{x}{1}

    \setcounter{y}{-1}
    \foreach \b in \a {
      \addtocounter{y}{1}

      \setcounter{z}{-1}
      \foreach \c in {0,...,\b} {
        \addtocounter{z}{1}

        \cubecolors{\a}
      \ifthenelse{\c=0}{\setcounter{z}{-1},\addtocounter{y}{0}}{
        \cube{\value{x}}{\value{y}}{\value{z}}}
      }
    }
  }
}

    \begin{document}
\begin{tikzpicture}
\planepartition{{5,3,2,2},{4,2,2,1},{3,2,1},{2,1},{1}}
\end{tikzpicture}
   \end{document}

答え1

を使用して色付けを行う方法があるはずだと私は思いますmodが、現時点では方法がわかりません (言い訳をすると、ちょっと遅すぎます)。ただし、その間、カウンター (便利ですが、それでも余分なコードです) と、パッケージおよびifthenxコマンド\ifthenelseを に置き換える代替案を提供できます\ifnum### ... \else ... \fi

したがって、\planepartitionコマンドを次のように置き換えることができます。

\newcommand\planepartition[1]{
  \foreach \a [count=\x starting from -1] in {#1} {
    \foreach \b [count=\y starting from -1] in \a {
      \foreach \c [count=\z starting from -1] in {0,...,\b} {
        \cubecolors{\a}
        \ifnum\c=0
        \else
            \cube{\x}{\y}{\z} 
        \fi
      }
    }
  }
}

関連情報