44

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}
15
  • 2
    Aww man, my contest has barely any entries already.
    – Canageek
    Dec 18, 2013 at 20:50
  • 2
    Some inspiration: natureknows.org/2013/11/… Dec 18, 2013 at 20:55
  • 3
    Nitpick: The right example above is no snowflake. They must be heaxagonal in some way.
    – Speravir
    Dec 18, 2013 at 21:02
  • 2
    @Thomas I'm upset now:-) Dec 18, 2013 at 21:26
  • 3
    @Thomas stephan meant my tree:-) Dec 18, 2013 at 21:42

3 Answers 3

78

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

6
  • 1
    Great job, you have the most impressive answer so far
    – Thomas
    Dec 19, 2013 at 10:30
  • These are very really truly high quality works. I salute you!
    – Pouya
    Dec 20, 2013 at 10:26
  • 2
    Thank you both, Thomas and @Pouya, for your kind words and for the fun question and answer, respectively :-)
    – JLDiaz
    Dec 20, 2013 at 10:57
  • 1
    Great example! I added it to the TeXample TikZ Gallery.
    – Stefan Kottwitz
    Feb 2, 2014 at 17:36
  • @StefanKottwitz Thank you! By the way, I'm the same "Jose Luis Diaz" which has two more examples at TeXample. You can merge both authors.
    – JLDiaz
    Feb 3, 2014 at 8:18
32
\documentclass{standalone}
\usepackage{tikz}
\usepackage{bbding} 
\usepackage[weather]{ifsym}
\begin{document}
    \begin{tikzpicture}
        \draw node[font=\fontsize{70}{70}]{\Snowflake\quad\SnowflakeChevron\quad\SnowflakeChevronBold\quad\Snow};
    \end{tikzpicture}
\end{document}

enter image description here


enter image description here

11
  • 16
    I don't think the one on the bottom is a scientifically accurate snowflake, just saying.
    – Canageek
    Dec 18, 2013 at 23:10
  • @Canageek and yet, sadly, that one looks like a snowflake more than mine =D
    – Bordaigorl
    Dec 19, 2013 at 0:12
  • 4
    @Pouya Problem ? :)
    – Thomas
    Dec 19, 2013 at 5:33
  • 2
    @Thomas, Not at all bor! I just took advantage of your question, not being specific about how to use Tikz. I hope my little joke wont spoil your cool question :)
    – Pouya
    Dec 19, 2013 at 9:54
  • 3
    That's very dirty. I like it. :P Dec 19, 2013 at 10:54
26

Not very proud of the output...but lazy enough not to enter some nice profile coordinates by hand =)

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows}
\newcommand{\profile}[1][]{
    \pgfmathsetseed{1234}
    \draw[snowflake,#1] (0:rnd) 
        \foreach \i in {1,...,10}{
            -- (rnd*15:rnd*3+\i)
        }
        -- ++(0:1) -- (0:15)
        \foreach \i in {15,...,20}{
            -- (rnd*15:rnd*7+\i)
        }
        -- ++(0:3)
        \foreach \i in {1,3,...,30}{
            -- (\i-rnd*3:30-rnd*3)
        }
        \foreach \i in {20,...,1}{
            -- (30-rnd*10:rnd*3+\i)
        };
}

\begin{document}
    \begin{tikzpicture}[
        snowflake/.style={
            fill=blue!10,
            draw=blue!40,
            drop shadow={shadow scale=1.01,shadow xshift=.6},
            line join=round,
            line cap=round,
            line width=5pt,
        }
    ]
    \foreach \a in {0,60,...,360}{
        \begin{scope}[rotate=\a]
            \profile
            \profile[cm={-1,0,0,1,(0,0)}]
        \end{scope}
    }
    \end{tikzpicture}
\end{document}

By changing the seed you get different snowflakes...fingers crossed!

Snowflake

1
  • 1
    That's impressive !
    – Thomas
    Dec 19, 2013 at 5:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .