3

There are ways to color a plane partition layer by layer; for instance, I have learned a lot from this post. I would like to color a partition with two colors, one color for a given leg in a corner, another color for all the other boxes.

Below is the code I am using. In the example, there is a "long" yellow leg (the x-axis), and I would like everything else to be, say, green. I can get everything on top of the yellow leg to become green, but not what's still next to the leg, namely "on the floor". I am sure this is a trivial problem but I really do not know how to modify the code.

\documentclass{article}

\usepackage{xifthen}
\usepackage{verbatim}

\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}
}

\newcommand*\cubecolors[1]{%
\ifcase#1\relax
  \or\colorlet{cubecolor}{yellow}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \else
    \colorlet{cubecolor}{blue}%
  \fi
}

% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\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 {1,...,\b} {
        \addtocounter{z}{1}
        \cubecolors{\c}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\usepackage{tikz}


\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.26]
\planepartition{{5,4,2,1},{3,2,1},{1,1},{1,1},{1},{1},{1},{1},{1},{1}}
\end{tikzpicture}
\end{figure}

\end{document}

1 Answer 1

1

Let me start by admitting that I have not even tried to understand the logic of your code. However, by just introducing a switch

 \pgfmathtruncatemacro{\myc}{ifthenelse(\value{y}+\value{z}==0,1,2)}
 \cubecolors{\myc}

which only tests if y and z are zero (you do not use negative numbers), I get

enter image description here

If you also have negative coordinates, use

\pgfmathtruncatemacro{\myc}{ifthenelse(abs(\value{y})+abs(\value{z})==0,1,2)}

instead.

Full code:

\documentclass{article}

\usepackage{xifthen}
\usepackage{verbatim}

\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}
}

\newcommand*\cubecolors[1]{%
\ifcase#1\relax
  \or\colorlet{cubecolor}{yellow}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \else
    \colorlet{cubecolor}{blue}%
  \fi
}

% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\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 {1,...,\b} {
        \addtocounter{z}{1}
        \pgfmathtruncatemacro{\myc}{ifthenelse(\value{y}+\value{z}==0,1,2)}
        \cubecolors{\myc}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\usepackage{tikz}


\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.26]
\planepartition{{5,4,2,1},{3,2,1},{1,1},{1,1},{1},{1},{1},{1},{1},{1}}
\end{tikzpicture}
\end{figure}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .