[Tex/LaTex] Nesting fractal tikz decorations (Koch snowflake)

tikz-pgf

I am trying to come up with some code to allow the use of a decoration (for example the Koch snowflake from decorations.fractals) where you provide a single parameter to determine how many times to decoration is applied (in a nested way). I have tried to use a pic, as outlined below, but it comes up with an errors to do with the decorator either having an empty argument or not being followed by a brace:

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

\begin{document}
\newcommand{\koch}[1]{
    \foreach \i in {1,...,#1}{decorate\{}
    (0,0)--(1,0)
    \foreach \i in {1,...,#1}{\}};
}

\tikzset{pics/koch/.style={decoration={Koch snowflake}
        code={\draw \koch{#1}}
    }
} 
\begin{tikzpicture}
    \path (0,0) pic {koch=4};
\end{tikzpicture}

\end{document}

I have tried a few variations on this (it says \pic is undefined) this code is saying that \tikz@parabola is undefined and the error seems to be between the i and c of pic (that is where the error message splits).

What I want in the end is some code so that I can do something like

\begin{tikzpicture}
  \draw (0,0) \koch{4};
  \draw (0,1) \koch{3};
\end{tikzpicture

To get the 3rd and 4th iterations of the Koch decorator on an interval. Even better I suppose would be to have something to pass a decorator and a number to so you can choose different fractal decorators to use.

Best Answer

Not quite the required answer but how about a Lindenmayer system instead?

\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{lindenmayersystems}

\tikzset{koch snowflake/.style={insert path={%
   l-system [l-system={rule set={F -> F-F++F-F}, axiom=F++F++F,
    step=0.75cm/3^#1, angle=60, order=#1,anchor=center}] -- cycle}}}

\begin{document}
\tikz
  \foreach \i in {0,...,4}
    \fill (0,\i) [koch snowflake=\i] node [text=white, font=\sf] {\i}; 

\end{document}

enter image description here