-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCantorCube.tex
58 lines (53 loc) · 1.73 KB
/
CantorCube.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
%参考:https://tex.stackexchange.com/questions/383399/tikz-fractal-menger-sponge
\documentclass{standalone}
%package
\usepackage{luatex85}
\usepackage{tikz}
%定义颜色
\definecolor{boundarycolor}{cmyk}{1,0,0,0}%Cyan
\definecolor{thirdcolor}{cmyk}{0.82,0.00,0.04,0.30}%LightSeaGreen
\definecolor{fillcolor}{cmyk}{0.12,0,0,0}%LightCyan
%定义\cantorcube命令
\newcommand\cantorcube[1]{
\pgfmathsetmacro\level{int(#1 - 1)}
\ifnum \level = 0 \relax
\shadedraw[right color = thirdcolor,left color = thirdcolor!90,line width=0,draw = fillcolor]
(1,1,1) -- (1,1,-1) -- (1,-1,-1) -- (1,-1,1) -- cycle; %右
\shadedraw[right color = boundarycolor,left color = boundarycolor!90 ,line width=0,draw = fillcolor]
(1,1,1) -- (1,1,-1) -- (-1,1,-1) -- (-1,1,1) -- cycle; %上
\shadedraw[right color = boundarycolor!50, left color = fillcolor!90,line width=0,draw = fillcolor]
(1,1,1) -- (1,-1,1) -- (-1,-1,1) -- (-1,1,1) -- cycle; %正
\else
\begin{scope}[scale=.3333333333]
\begin{scope}[shift={(-2, -2, -2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(2, -2, -2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(-2, 2, -2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(2, 2, -2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(-2, -2, 2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(2, -2, 2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(-2, 2, 2)}]
\cantorcube{\level}
\end{scope}
\begin{scope}[shift={(2, 2, 2)}]
\cantorcube{\level}
\end{scope}
\end{scope}
\fi
}
\begin{document}
\begin{tikzpicture}
\cantorcube{2}
\end{tikzpicture}
\end{document}