我无法进一步塑造我的形状。我怎样才能画得更多

我无法进一步塑造我的形状。我怎样才能画得更多

我无法不断重复角落中的形状。我无法发出角落之类的命令。我希望它像分形一样循环继续,但我无法进行循环。使用我编写的命令,相同的形状不会在小粉红色角落上再次绘制,你能帮助我吗?

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{caption}
\tikzset{
    buffer/.style={
        draw,
        regular polygon,
        regular polygon sides=4,
        minimum size=20em
    },
    pics/nine/.style 2 args= {code={ 
            \node[buffer, fill=#1] (A) {};
            \foreach \mycorner in {1,2,3,4}
            \node[buffer, fill=#2, scale=.33, transform canvas] at (A.corner \mycorner) {};
    }},
}
\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}
            \node[buffer, fill=pink] (B) {};
            \foreach \mycorner in {1,2,3,4}
            \pic[scale=.33, transform shape] at (B.corner \mycorner) {nine={green}{pink}};
        \end{tikzpicture}
        \caption{Number 4}
    \end{figure}
\end{document}

答案1

我确信有更好的解决方案,但是使用 TikZ,这个非常简单:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{caption}

\tikzset{
    buffer/.style={
        draw,
        regular polygon,
        regular polygon sides=4,
        minimum size=20em
    },
}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
        \node[buffer, fill=pink]{};
    \end{tikzpicture}
    \caption{One square}
\end{figure}
\begin{figure}
    \centering
    \begin{tikzpicture}
        \node[buffer, fill=pink] (A) {};
        \foreach \mycorner in {1,2,3,4}
            {\node[buffer, fill=green,scale=.33, transform shape] (A\mycorner) at (A.corner \mycorner) {};} 
    \end{tikzpicture}       
    \caption{One square with squares}
\end{figure}
\begin{figure}
\centering
    \begin{tikzpicture}
        \node[buffer, fill=pink] (A) {};
        \foreach \mycorner in {1,2,3,4}
            {\node[buffer, fill=green,scale=.33, transform shape] (A\mycorner) at (A.corner \mycorner) {};} 
        \foreach \mycornerone in {1,2,3,4}
            {\foreach \mycornertwo in {1,2,3,4}
                {\node[buffer, fill=pink,scale=.11, transform shape] at (A\mycornerone.corner \mycornertwo) {};}}
    \end{tikzpicture}       
    \caption{One square with squares with squares}
\end{figure}
    \begin{figure}
\centering
    \begin{tikzpicture}
        \node[buffer, fill=pink] (A) {};
        \foreach \mycorner in {1,2,3,4}
            {\node[buffer, fill=green,scale=.33, transform shape] (A\mycorner) at (A.corner \mycorner) {};} 
        \foreach \mycornerone in {1,2,3,4}
            {\foreach \mycornertwo in {1,2,3,4}
                {\node[buffer, fill=pink,scale=.11, transform shape] (A\mycornerone\mycornertwo) at   (A\mycornerone.corner \mycornertwo) {};}}
        \foreach \mycornerone in {1,2,3,4}
            {\foreach \mycornertwo in {1,2,3,4}
              {\foreach \mycornerthree in {1,2,3,4}
                {\node[buffer, fill=green,scale=.0367, transform shape] at (A\mycornerone\mycornertwo.corner \mycornerthree) {};}}}
    \end{tikzpicture}       
    \caption{One square with squares with squares with squares}
\end{figure}
\end{document}

在此处输入图片描述

答案2

这是一种进行递归绘制的方法元帖子使用luamplib。您需要使用 来编译它lualatex

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb

def do(expr s, level) = 
    fill s withcolor if odd level: Blues else: Reds fi [8][1+level];
    draw s;
    if level > 0:
        for i=1 upto length s:
            do(s shifted - center s scaled 7/16 shifted point i of s, level - 1);
        endfor
    fi
enddef;

beginfig(1);
    do(unitsquare scaled 200, 5);
endfig;
\end{mplibcode}
\end{document}

您可能需要调整缩放参数以获得不同的效果,也可以尝试其他路径。但不要尝试超过 6 或 7 个级别,因为这将花费很长时间。

相关内容