再次尝试使用 Tikz 绘制分形。我正在尝试绘制 Sierpinski 平铺箭头:
通过使用 L 系统。我找到的是:
\pgfdeclarelindenmayersystem{SierpLine}{
\symbol{a}{\pgflsystemsetangle{300}}
\symbol{b}{\pgflsystemsetangle{60}}
\rule{X -> YFa+XFa+Y}
\rule{F -> XFb+YFb+X}
}
其中a
和b
是角度的旋转。“零次”迭代是单位间隔,然后我的图像就变得很歪斜。有人能帮忙吗?
我的代码:
\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\pgfdeclarelindenmayersystem{SierpArr}{
\symbol{a}{\pgflsystemsetangle{300}}
\symbol{b}{\pgflsystemsetangle{60}}
\rule{X -> YFa+XFa+Y}
\rule{F -> XFb+YFb+X}
}
\tikz;
\tikz\draw[lindenmayer system={SierpArr,axiom=S,step=80pt,order=1}]lindenmayer system;
\tikz\draw[lindenmayer system={SierpArr,axiom=S,step=80pt,order=2}]lindenmayer system;
\tikz\draw[lindenmayer system={SierpArr,axiom=S,step=80pt,order=3}]lindenmayer system;
\end{document}
答案1
这是手册中的一个示例。
输出
代码
\documentclass[border=9,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\pgfdeclarelindenmayersystem{SierpArr}{
\symbol{X}{\pgflsystemdrawforward}
\symbol{Y}{\pgflsystemdrawforward}
\rule{X -> Y-X-Y}
\rule{Y -> X+Y+X}
}
\foreach \k in {1,...,7}
{
\tikz\draw[lindenmayer system={SierpArr,angle=60,axiom=X,step=200pt/2^\k,order=\k}]lindenmayer system;
}
\end{document}