
다른 색상의 레이어를 생성하는 아래 코드를 사용하고 있습니다. 세 축의 각 레이어에 대해 동시에 작동하도록 하려면 장식을 얻는 데 어려움이 있습니다. 여기에 도움을 주세요. a, b, c 세 가지 색상을 사용하여 a+b+c mod 3으로 위치 (a, b, c)에 있는 상자를 색칠하려고 합니다.
암호
% 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
}
}
}
}