但是,我无法按照标记的路线行驶。
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\def\side{1}
\foreach \j in {1,...,5}{
\begin{scope}[shift={(-60:\side*\j)}]
\foreach \i in {1,...,\j}{
\begin{scope}[shift={(0:-\side*\i)}]
\tkzDefPoint (0,0){A}
\tkzDefPoint (0:\side){B}
\tkzDefPoint (60:\side){C}
\tkzDrawPolygon[top color=LightSteelBlue4](A,B,C)
\end{scope}
}
\end{scope}
}
\end{tikzpicture}
\end{document}
答案1
这个turtle
库可以在这里使用,虽然重写“金字塔”代码使得定位乌龟的起点变得更容易一些:
\documentclass[border=5]{standalone}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{turtle}
\tikzset{turtle/.cd,
S/.style={home, left=180},
L/.style={left=60, forward},
R/.style={right=60, forward},
F/.style={forward}
}
\begin{document}
\begin{tikzpicture}[line join=round, line cap=round, very thick]
\foreach \i in {0,...,4}
\foreach \j [evaluate={\x=(\j*2-\i)*cos(30); \y=-\i*1.5;}] in {0,...,\i}
\draw [shift={(\x,\y)}, top color=LightSteelBlue4]
(90:1) -- (210:1) -- (330:1) -- cycle;
\draw [turtle={
S, F, L, R, R, R, L, L, L, L, R, L, R, R, R, R, L, R, L, R, L
}];
\end{tikzpicture}
\end{document}