# Tikz Fractals - How can I create this snowflake pattern?

I am playing around with tikz and am trying to reproduce the figure below:

My code so far is as below,

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals}

\begin{document}
\begin{tikzpicture}[font=\footnotesize, decoration=Koch curve type 1]
%%%%%%%%%%%%%%% Shape 1
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
%%%%%%%%%%%%%%%
\draw (A) rectangle (C);
\node at (1.5,1.5) {$S_1$};
%%%%%%%%%%%%%%% Shape 2
\begin{scope}[xshift=5cm]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
%%%%%%%%%%%%%%%
\draw decorate{ (D) -- (C) -- (B) -- (A) -- cycle};
\node at (1.5,1.5) {$S_2$};
\end{scope}
%%%%%%%%%%%%%%% Shape 3
\begin{scope}[xshift=11cm]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
%%%%%%%%%%%%%%%
\draw decorate{ decorate{ (D) -- (C) -- (B) -- (A) -- cycle} };
\node at (1.5,1.5) {$S_3$};
\end{scope}
%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}


producing the output:

I can not get the third picture right.

The rule: Subsequent terms are obtained by replacing the middle third of each external edge of a new square formed in the previous snowfake, by a square 1/3 of the size.

Obviously I have to fiddle with the Koch curve definition but my knowledge of the library is very limited to do so. Any help is very appreciated.

• This seems to be the expected behaviour of Koch curve type 1 fractals – BambOo Apr 29 '18 at 12:53
• Did you check section 55 Lindenmayer system drawing library of the pgfmanual version 3.0.1a ? – BambOo Apr 29 '18 at 12:57

Maybe not the most elegant answer, but it could be useful.

\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{decorations.fractals}

% Creates a "_|-|_" looking shape defined by the start position, the start angle and the length of every segment of the path
\newcommand{\decoratededge}[3]{
\draw #1 -- ++ (90+#2:#3) decorate{--++ (180+#2:#3) --++ (90+#2:#3) --++ (0+#2:#3)} --++ (90+#2:#3);
}

\begin{document}
% Draws the manually defined 5 segment path
\begin{tikzpicture}
\decoratededge{(0,0)}{0}{1/3}
\end{tikzpicture}
% Draws the manually defined 5 segment path with a decoration of the 3 middle segments
\begin{tikzpicture}[font=\footnotesize, decoration=Koch curve type 1]
\decoratededge{(0,0)}{0}{1/3}
\end{tikzpicture}
% Draws the complete figure
\begin{tikzpicture}[font=\footnotesize, decoration=Koch curve type 1]
\decoratededge{(0,0)}{0}{1/3}
\decoratededge{(0,1)}{-90}{1/3}
\decoratededge{(1,1)}{-180}{1/3}
\decoratededge{(1,0)}{-270}{1/3}
\end{tikzpicture}
\end{document}


Result:

• Thanks a lot for the answer, your approach does indeed what I had in mind. – Thanasis Apr 29 '18 at 15:11
• I had a look at the lindenmayer library, but It is not that simple to use at first sight. I hope it helps – BambOo Apr 29 '18 at 15:17