有谁知道如何用 tikz 做这样的事情吗?:
我想创建几乎相同的东西,只用一条路径,厚度为 1 点,没有眼睛等...谢谢
路径示例:
0,0,0; 1,1,1; 2,2,2; 3,3,3; 3,4,4; 4,5,4; 5,6,5; 6,7,6; 7,8,7; 8,9,8; 9,10,8; 10,11,9; 11,12,10; 12,13,11; 13、14、12; 14,14,13; 15,14,14; 16,15,15; 16,16,16; 17,17,17; 17,17,18; 17,17,19; 17,17,20; 18、17、21; 19、17、22; 20、17、23; 21、18、24; 22、19、24; 23、20、24; 23、21、24; 23、22、24; 24,23,24; 24,24,24;
答案1
可能是这样的:
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{backgrounds}
\def\drawcube{%
\begin{pgfonlayer}{background}
\path [fill=gray, draw=white]
(\x, \y, 0) -- (\x+1, \y, 0) --
(\x+1, \y+1, 0) -- (\x, \y+1, 0) -- cycle
(\x, 0, \z) -- (\x+1, 0, \z) --
(\x+1, 0, \z+1) -- (\x, 0, \z+1) -- cycle
(0, \y,\z) -- (0, \y+1, \z) --
(0, \y+1, \z+1) -- (0, \y, \z+1) -- cycle;
\end{pgfonlayer}
\path [draw=black]
(\x, \y, \z) -- (\x+1, \y, \z) --
(\x+1, \y+1, \z) -- (\x, \y+1, \z) -- cycle
(\x, \y, \z+1) -- (\x+1, \y, \z+1) --
(\x+1, \y+1, \z+1) -- (\x, \y+1, \z+1) -- cycle
(\x, \y, \z) -- (\x, \y, \z+1)
(\x+1, \y, \z) -- (\x+1, \y, \z+1)
(\x+1, \y+1, \z) -- (\x+1, \y+1, \z+1)
(\x, \y+1, \z) -- (\x, \y+1, \z+1);
\pgfmathsetmacro\r{random(1,3)}%
\ifcase\r
\or\pgfmathsetmacro\x{min(\N,\x+1)}%
\or\pgfmathsetmacro\y{min(\N,\y+1)}%
\or\pgfmathsetmacro\z{min(\N,\z+1)}%
\fi%
}
\begin{document}
\begin{tikzpicture}[every path/.style={very thick, line cap=round, line join=round,scale=0.5}]
\def\N{10}
\begin{pgfonlayer}{background}
\foreach \x in {0,...,\N}
\foreach \y in {0,...,\N}
\path [fill=gray!20, draw=white]
(\x, \y, 0) -- (\x+1, \y, 0) -- (\x+1,\y+1,0) -- (\x, \y+1,0) -- cycle
[rotate around x=90]
(\x, \y, 0) -- (\x+1, \y, 0) -- (\x+1,\y+1,0) -- (\x, \y+1,0) -- cycle
[rotate around x=-90, rotate around y=-90]
(\x, \y, 0) -- (\x+1, \y, 0) -- (\x+1,\y+1,0) -- (\x, \y+1,0) -- cycle;
\end{pgfonlayer}
\def\x{0}\def\y{0}\def\z{0}
\pgfmathloop
\pgfmathparse{int((\x==\N) && (\y==\N) && (\z==\N))}
\ifnum\pgfmathresult=1
\drawcube
\else
\drawcube
\repeatpgfmathloop
\draw [white, ultra thick]
(\N+1, \N+1, \N+1) -- (\N+1, 0, \N+1) --
(\N+1, 0, 0) -- (\N+1,\N+1,0) -- cycle --
(0, \N+1, \N+1) -- (0, 0, \N+1) -- (\N+1, 0, \N+1);
\begin{pgfonlayer}{background}
\draw [gray, ultra thick]
(0,0,0) -- (\N+1,0,0) (0,0,0) -- (0,\N+1,0) (0,0,0) -- (0,0,\N+1);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}