
Существуют способы раскрашивания плоской перегородки слой за слоем; например, я многому научился уэта почта. Я хотел бы покрасить перегородку двумя цветами: один цвет для заданной ножки в углу, другой цвет для всех остальных коробок.
Ниже приведен код, который я использую. В примере есть "длинная" желтая нога (ось x), и я хотел бы, чтобы все остальное было, скажем, зеленым. Я могу сделать так, чтобы все, что находится наверху желтой ноги, стало зеленым, но не то, что все еще находится рядом с ногой, а именно "на полу". Я уверен, что это тривиальная проблема, но я действительно не знаю, как изменить код.
\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
Позвольте мне начать с признания, что я даже не пытался понять логику вашего кода. Однако, просто введя переключатель
\pgfmathtruncatemacro{\myc}{ifthenelse(\value{y}+\value{z}==0,1,2)}
\cubecolors{\myc}
который проверяет только если y
и z
равны нулю (вы не используете отрицательные числа), я получаю
Если у вас также есть отрицательные координаты, используйте
\pgfmathtruncatemacro{\myc}{ifthenelse(abs(\value{y})+abs(\value{z})==0,1,2)}
вместо.
Полный код:
\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}