[Tex/LaTex] Your best snowflake with Tikz

funtikz-pgf

Christmas is coming, show me your best snowflakes made with Tikz 🙂

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.fractals}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[decoration=Koch snowflake]
    \draw decorate{decorate{decorate{decorate{(0,0) -- (3,0)}}}};
    \draw decorate{decorate{decorate{decorate{(3,0) -- (1.5,-3)}}}};
    \draw decorate{decorate{decorate{decorate{(1.5,-3) -- (0,0)}}}};
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[axis lines=none]
\addplot+[domain=0:2*pi,samples=1000,mark=none, color=black]
({10*cos(deg(x)) + 2*cos(deg(4*deg(x))) +  2*cos(deg(10*deg(x)))},
{10*sin(deg(x)) + 2*sin(deg(4*deg(x))) +  2*sin(deg(10*deg(x)))});
\end{axis}
\end{tikzpicture}

\end{document}

EDIT :

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shadings}
\definecolor{LightBlack}{rgb}{.4,.4,.4}
\definecolor{SoftBlack}{rgb}{.2,.2,.2}

\begin{document}

\begin{tikzpicture}
\fill[top color=LightBlack,bottom color=SoftBlack] (-1,6) rectangle (8,0);
\begin{axis}[axis lines=none]
\addplot+[domain=0:2*pi,samples=37,mark=none, color=white]
({10*cos(10*deg(x)) + 1*cos(2*deg(x)) +  0.2*cos(deg(x)) + 0.1 * cos(0.5*deg(x))},
{10*sin(10*deg(x)) + 1*sin(2*deg(x)) +  0.2*sin(deg(x)) + 0.1 * sin(0.5*deg(x))});
\end{axis}
\end{tikzpicture}

\end{document}

Best Answer

I think the best approach is to use Lindenmayer systems.

The following code defines a Lindenmayer rules for drawing a single "arm" of the snowflake. I think it is crucial that the "arm" is symmetric. Then this arm is repeated rotated 60 degrees each time to produce the complete snowflake.

Changing the Lindenmayer rule, the angle turned by the rules + and -, and the line width, an astonishing number of possibilities flourish. Unfortunately these kind of figures take a time to compile, so I became impatient before trying other rules, and I decided to post the preliminary results. But it is so much fun to play with these parameters that I'll probably come back with more designs :-)

The following figure uses only two rules, which I named "A" and "B":

  1. Rule A: F -> FF[+F][-F]
  2. Rule B: F -> ffF[++FF][--FF]

Snowflakes

The snowflakes in each row use the same rule and angle, and the different aspect is due only to change in the line width. The rules and angles for each row are:

  • Row 1. Rule A, angle 60
  • Row 2. Rule A, angle 90
  • Row 3. Rule B, angle 60
  • Row 4. Rule B, angle 30

This is the code:

\documentclass{article}
\usepackage{tikz,nopageno}
\usetikzlibrary{lindenmayersystems}

\pgfdeclarelindenmayersystem{A}{
    \rule{F -> FF[+F][-F]}
}

\pgfdeclarelindenmayersystem{B}{
    \rule{F -> ffF[++FF][--FF]}
}

\tikzset{
    type/.style={l-system={#1, axiom=F,order=3,step=4pt,angle=60},
      blue, opacity=0.4, line width=.5mm, line cap=round   
    },
}

\newcommand\drawsnowflake[2][scale=0.2]{
    \tikz[#1]
    \foreach \a in {0,60,...,300}  {
    \draw[rotate=\a,#2] l-system;
    };
}

\begin{document}
\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake{type=A, line width=\width mm} }

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake[scale=0.3]{type=A, l-system={angle=90}, line width=\width mm} }    

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake[scale=0.3]{type=B, line width=\width mm} }

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake{type=B, l-system={angle=30}, line width=\width mm} }

\end{document}

I have to play with the axiom too! :-)

Update

Inspired by the page suggested by Torbjørn T., I tried to reproduce the first one:

Snow

For that I used a new rule:

\pgfdeclarelindenmayersystem{C}{
    \symbol{G}{\pgflsystemdrawforward}
    \rule{F -> F[+F][-F]FG[+F][-F]FG}
}

And the flakes were drawn with:

\drawsnowflake[scale=0.2]{type=C, l-system={order=2}, line width=0.2mm}
\drawsnowflake[scale=0.2]{type=C, l-system={order=2}, line width=0.4mm}

Update: Playing with axioms

The same rule (C) used in previous example can produce different variations if we start with an axiom different of the simple F.

Variations

I devised a new rule, aimed to produce flakes of the type "plate", which can also produce interesting variations depending on the axiom. This is the rule:

\pgfdeclarelindenmayersystem{D}{
    \symbol{G}{\pgflsystemdrawforward}
    \symbol{H}{\pgflsystemdrawforward}
    \rule{F -> H[+HG][-HG]G}
    \rule{G -> HF}
}

And these are some variations:

\drawsnowflake[scale=0.5]{type=D, l-system={order=4,angle=60,axiom=GF}, line width=0.7mm}
\drawsnowflake[scale=0.5]{type=D, l-system={order=4,angle=60,axiom=GfF}, line width=0.7mm}
\drawsnowflake[scale=0.5]{type=D, l-system={order=4,angle=60,axiom=FG}, line width=0.7mm}
\drawsnowflake[scale=0.5]{type=D, l-system={order=4,angle=60,axiom=FfG}, line width=0.7mm}

Plates