12

I draw a Koch Snowflake in TikZ. My code is below.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,intersections}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}[scale=2.2,decoration=Koch snowflake]
\draw[] decorate{decorate{decorate{decorate{decorate{ (-1.732,0) -- (0,3) -- (1.732, 0) -- (-1.732, 0)}}}}} ;
\end{tikzpicture}
\end{document}

I am wondering if it is possible to make a similar animation of this snowflake as in Animated Mandelbrot. I tried to change the code in this post, but it is too difficult for me. May I ask for help in this?

  • Do you want "shift-and-scale.gif" or "one-more-iteration.gif"? – Symbol 1 Dec 6 '17 at 20:35
27
\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{arrows,intersections}
\usetikzlibrary{decorations.fractals}
\begin{document}
\def\n{10}
\foreach\i in{1,...,\n}{
    \tikz{
        \clip(-6,-.1)rectangle(6,3.5);
        \tikzset{shift={(0,3.4641016151)},scale={pow(3,\i/\n)},shift={(0,-3.4641016151)}}
        \draw[decoration=Koch snowflake,opacity=1-\i/\n]      {decorate{decorate{decorate{decorate{decorate{(-6,0)--(6,0)}}}}}};
        \draw[decoration=Koch snowflake,opacity=\i/\n]decorate{decorate{decorate{decorate{decorate{decorate{(-6,0)--(6,0)}}}}}};
    }
}
\end{document}

EDIT

There are other fixed points, e.g.

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{arrows,intersections}
\usetikzlibrary{decorations.fractals}
\begin{document}
\def\n{20}
\foreach\i in{1,...,\n}{
    \tikz{
        \clip circle(4);
        \tikzset{scale={pow(3,\i/\n)},rotate=60*\i/\n}
        \draw[decoration=Koch snowflake]decorate{decorate{decorate{decorate{decorate{(-6.4285714,-1.2371791)--(3.5714286,-1.2371791)}}}}} ;
        \scoped[transparency group,opacity=\i/\n]\draw[decoration=Koch snowflake,fill=white]
                               decorate{decorate{decorate{decorate{decorate{decorate{(-6.4285714,-1.2371791)--(3.5714286,-1.2371791)}}}}}};
    }
}
\end{document}

without rotation

  • Amazing this fits into 14 lines of TikZ code. – usr1234567 Dec 7 '17 at 6:10
  • 2
    @usr1234567: It doesn't, there's a fractals library. – einpoklum Dec 7 '17 at 12:37
  • Well the recursive nature of fractales make them easy to draw in TeX. I bet it can be done in 1000 characters with vanilla-PGF. – Symbol 1 Dec 8 '17 at 3:03
14
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}

\tikzset{
  Koch curve/.style = {
    l-system={
      rule set={F -> F-F++F-F},
      axiom=F++F++F,
      step=1pt,
      angle=60,
      #1
    }
  }
}

\begin{document}

\foreach \order in {1,...,6,5,4,3,2} {
  \begin{tikzpicture}
    \draw[Koch curve={order=\order,step=500pt/3^(\order)}] l-system -- cycle;
  \end{tikzpicture}
}

\end{document}

enter image description here

8

you need http://tug.org/~hvoss/pst-koch2.sty and http://tug.org/~hvoss/pst-koch2.tex

\documentclass{article}
\usepackage{multido}
\usepackage{pst-koch2}
\pagestyle{empty}
\begin{document}

\multido{\iA=90+-1}{31}{%
\begin{pspicture}(-5.1,-5.1)(5.1,5.1)
  \psframe*(-5,-5)(5,5)
  \psKoch[N=4,base=squareB,motif=cesaro,angle=\iA,HSB=false,linestyle=none,fillstyle=solid,fillcolor=cyan,linecolor=red]
  \psKoch[N=4,base=squareB,motif=cesaro,angle=\iA]
\end{pspicture}\newpage}

\end{document}

enter image description here

there is also a bigger image: http://tug.org/~hvoss/koch.gif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.