Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to use TikZ for drawing a christmas tree. Here's a start, I used the lindenmayersystems library for drawing a tree:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\begin{tikzpicture}
\draw [color=green!50!black, l-system={rule set={S -> [+++G][---G]TS,
  G -> +H[-G]L, H -> -G[+H]L, T -> TL, L -> [-FFF][+FFF]F}, step=4pt, angle=18,
 axiom=+++++SLFFF, order=11}] lindenmayer system -- cycle;
\end{tikzpicture}
\end{document}

Fractal tree

I found the tree in "The Science of fractal images" by Peitgen and Saupe.

Who can help to decorate it? Or to draw another tree with Christmas decorations, such as tinsel garland (lametta), candles, baubles (Christmas balls), a tree topper? Perhaps add a shading to the green?

For celebrating Christmas, I would like to put the tree on our blog, and on the TikZ example gallery.

share|improve this question
1  
I don't know if I'll get a chance to figure out the details of this so I'll record the idea as inspiration for domeone else to realise: for tinsel, try a curve with the snake decoration and rounded corners as in tex.stackexchange.com/q/38989/86 by adjusting the parameters then you get quite a variety of tinsel-like effects – Andrew Stacey Dec 23 '11 at 6:18
(Botheration. The iPad keyboard strikes again: "someone". And I haven't the accuracy to hit the "edit" link.) – Andrew Stacey Dec 23 '11 at 6:20
4  
I'm very happy Kjell accepts your offer to become the new maintainer of TeXample.net. It's a very good news ! Happy christmas Stephan !! – Alain Matthes Dec 24 '11 at 10:30
4  
+1 for the {trees} tag :D – doncherry Dec 24 '11 at 12:32

9 Answers

up vote 83 down vote accepted

Merry Christmas everyone!

\documentclass[11pt]{scrartcl} 
\usepackage[dvipsnames,svgnames]{xcolor}  
\usepackage{tikz}
\usetikzlibrary{shapes,decorations.shapes}
\newsavebox{\mycandle}
\savebox{\mycandle}{ 
\begin{tikzpicture}[scale=.1]
\shade[top color=yellow,bottom color=red] (0,0) .. controls (1,.2) and (1,.5) .. (0,2) .. controls (-1,.5)  and  (-1,.2) .. (0,0);
\fill[yellow!90!black] (.8,0) rectangle (-.8,-5); 
\end{tikzpicture} } 

\tikzset{
  paint/.style={draw=#1!50!black, fill=#1!50},
  my star/.style={decorate,decoration={shape backgrounds,shape=star},
                  star points=#1}
}  

\begin{document}
\begin{tikzpicture} 
   \draw[fill=Maroon,ultra thick] 
   (.75,-1)  ..  controls (.5,.5)  and   (.5,3)    .. (0.5,4) 
-- (-0.5,4)  ..  controls (-.5,3) and (-.5,.5)     .. (-.75,-1) ;
\draw[ultra thick,fill=green!50!black] 
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7) 
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25) 
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2) 
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4) 
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25) 
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ;
\foreach \candle in {(2,5),(-2,5),(0.5,7.5),(-0.5,7.5),(-3,2.5), (3,2.5),
                    (1.5,1.75),(-1.5,1.75)}
\node at \candle {\usebox{\mycandle}} ; 
 \node [star, star point height=.5cm, minimum size=.5cm, draw,fill=yellow,thick]
       at (0,10) {};
       \begin{scope}[decoration={shape sep=.2cm, shape size=.25cm}] 
    \draw [my star=6, paint=red]  (-4,2)
             ..  controls (0,2)     and   (1,3.5)   .. (1,4.5)
             ..  controls (1,6)     and   (0.5,6)      .. (0.5,7.25); 
    \draw [my star=6, paint=blue]  (4,2)
             ..  controls  (0,2) and (-1,3.5)      .. (-1,4.5)             
             ..  controls (-1,6)     and   (-0.5,6)      .. (-0.5,7.25);    
       \end{scope}  
\end{tikzpicture}

\end{document} 

enter image description here

Update version 2 : The snow arrives, I added some balls and a shade on the tree

\documentclass[11pt]{scrartcl} 
\usepackage[dvipsnames,svgnames]{xcolor}  
\usepackage{tikz}
\usetikzlibrary{%
  shapes,
  decorations.shapes,
  decorations.fractals,
  decorations.markings,
  shadows
}

\newsavebox{\mycandle}
\savebox{\mycandle}{ 
\begin{tikzpicture}[scale=.1]
\shade[top color=yellow,bottom color=red] (0,0) .. controls (1,.2) and (1,.5) .. (0,2) .. controls (-1,.5)  and  (-1,.2) .. (0,0);
\fill[yellow!90!black] (.8,0) rectangle (-.8,-5); 
\end{tikzpicture} } 

\tikzset{
  paint/.style={draw=#1!50!black, fill=#1!50},
  my star/.style={decorate,decoration={shape backgrounds,shape=star},
                  star points=#1}
}  

\begin{document}
  \begin{tikzpicture}[  ball red/.style={
    decorate,
    decoration={
      markings,
      mark=between positions .2 and 1 step 3cm
      with
      {
        \pgfmathsetmacro{\sz}{2 + .5 * rand}
        \path[shading=ball,ball color=red] (0,0) circle[radius=\sz mm];
      }
    }
  } ,ball blue/.style={
    decorate,
    decoration={
      markings,
      mark=between positions 0.1 and .9 step 3cm
      with
      {
        \pgfmathsetmacro{\sz}{2 + .5 * rand}
        \path[shading=ball,ball color=blue] (0,0) circle[radius=\sz mm];
      }
    }
  }   
]

\draw[fill=Maroon,ultra thick] 
      (.75,-1)  ..  controls (.5,.5)  and   (.5,3)    .. (0.5,4) 
   -- (-0.5,4)  ..  controls (-.5,3) and (-.5,.5)     .. (-.75,-1) ;
\shade[ultra thick, top color=green!90!black,bottom color=green!10!black] 
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7) 
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25) 
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2) 
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4) 
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25) 
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ;

\foreach \candle in {(2,5),(-2,5),(0.5,7.5),(-0.5,7.5),(-3,2.5), (3,2.5),
                    (1.5,1.75),(-1.5,1.75)}
\node at \candle {\usebox{\mycandle}} ; 
\node [star, star point height=.5cm, minimum size=.5cm,draw,fill=yellow,thick]
      at (0,10) {};
\begin{scope}[decoration={shape sep=.2cm, shape size=.25cm}] 
    \draw [my star=6, paint=red]  (-4,2)
             ..  controls (0,2)     and   (1,3.5)   .. (1,4.40); 
    \draw [my star=6, paint=red]  (-1.5,5.40)
             ..  controls (0,5.40)     and   (0.5,6.5)      .. (0.5,7);  
    \draw [my star=6, paint=blue]  (4,2)
             ..  controls  (0,2) and (-1,3.5)      .. (-1,4.40);             
    \draw [my star=6, paint=blue]  (1.5,5.40)
             ..  controls (0,5.40)     and   (-0.5,6.5)      .. (-0.5,7);     
\end{scope} 
% the balls
\path[ball red] 
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7) 
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25) 
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2) 
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4) 
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25) 
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ; 
\path[ball blue] 
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7) 
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25) 
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2) 
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4) 
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25) 
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ; 
 % the snow
\foreach \i in {0.5,0.6,...,1.6}
     \fill [white!80!blue,decoration=Koch snowflake,opacity=.9]
           [shift={(rand*5,rnd*8)},scale=\i]
           [double copy shadow={opacity=0.2,shadow xshift=0pt,
           shadow yshift=3*\i pt,fill=white,draw=none}]
        decorate {
          decorate {
            decorate {
              (0,0) -- ++(60:1) -- ++(-60:1) -- cycle
            }
          }
        };                  
\end{tikzpicture}

\end{document} 

enter image description here

share|improve this answer
8  
I love the elegance of this one. – Andrew Stacey Dec 23 '11 at 21:45
Beautiful! I put this one to our blog right now. – Stefan Kottwitz Dec 24 '11 at 14:48
3  
I like the Koch snowflakes! Great idea. – Harold Cavendish Dec 24 '11 at 21:22
The output is nice, but the input didn't look very christmasy so I optimised it a bit in an answer below. – David Carlisle Oct 26 '12 at 9:16
@AlainMatthes I want to support 'Tents and Trees' puzzle in my logicpuzzle package and need some kind of tree. I've modified your tree a bit. May I kindly ask you for a waiver (based on cc-wiki) to use your code in logicpuzzle.sty and license it under LPPL? – Josef May 3 at 13:04
show 1 more comment

Christmas Tree

Just in case the code isn't clear from behind the picture, here it is in full:

\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{%
  lindenmayersystems,
  decorations.pathmorphing,
  decorations.markings,
  shapes.geometric,
  calc%
}
\tikzset{
  tinsel/.style={
    #1,
    rounded corners=10mm,
    ultra thin,
    decorate,
    decoration={
      snake,
      amplitude=.1mm,
      segment length=10,
    }
  },
  baubles/.style={
    decorate,
    decoration={
      markings,
      mark=between positions .3 and 1 step 2cm
      with
      {
        \pgfmathsetmacro{\brad}{2 + .5 * rand}
        \path[shading=ball,ball color=#1] (0,0) circle[radius=\brad mm];
      }
    }
  },
  lights/.style={
    decorate,
    decoration={
      markings,
      mark=between positions 0 and 1 step 1cm
      with
      {
        \pgfmathparse{rand > 0 ? "dart" : "kite"}
        \let\lshape\pgfmathresult
         \pgfmathsetmacro{\tint}{100*rnd}
        \node[rotate=90,\lshape,shading=ball,inner sep=1pt,ball color=red!\tint!yellow] {};
      }
    }
  }
}

\begin{document}
\begin{center}
\tikz[remember picture,overlay] \coordinate (star) at (0,-1);
\end{center}

\lstinputlisting[
  breaklines=true,
  language=TeX,
  basicstyle=\tiny,
  firstline=63,
  lastline=103]{\jobname.tex}

\begin{tikzpicture}[overlay,remember picture]
\path (star) +(-50:7) coordinate (rhs) +(-130:7) coordinate (lhs);
\draw[brown!50!black,line width=5mm,line cap=round] (star) ++(-90:6.8) -- ++(0,-1) coordinate (base);
\node[scale=-1,trapezium,fill=black,minimum size=1cm] at (base) {};
\foreach \height/\colour in {%
  .2/blue,
  .4/yellow,
  .6/red,
  .8/orange,
  1/pink%
} {
  \draw[tinsel=\colour] ($(star)!\height!(lhs)$) to[bend right] ($(star)!\height!(rhs)$);
}
\path (star);
\pgfgetlastxy{\starx}{\stary}
\begin{scope}[xshift=\starx,yshift=\stary,yshift=-7cm]
\draw[color=green!50!black, l-system={rule set={S -> [+++G][---G]TS,  G -> +H[-G]L, H -> -G[+H]L, T -> TL, L -> [-FFF][+FFF]F}, step=4pt, angle=18, axiom=+++++SLFFF, order=11}] lindenmayer system -- cycle;
\end{scope}
\foreach \height/\colour in {%
  .1/pink,
  .3/red,
  .5/yellow,
  .7/blue,
  .9/orange%
} {
  \draw[tinsel=\colour] ($(star)!\height!(lhs)$) to[bend right] ($(star)!\height!(rhs)$);
}
\foreach \height in {.15,.35,...,1} {
  \draw[lights]  ($(star)!\height!(lhs)$) to[bend right] ($(star)!\height!(rhs)$);
}
\foreach \angle/\colour in {
  -50/red,
  -70/yellow,
  -90/blue,
  -110/pink,
  -130/purple%
} {
  \draw[baubles=\colour] (star) -- ++(\angle:7);
}
\node[star,star point ratio=2.5,fill=yellow,minimum size=1cm] at (star) {};
\end{tikzpicture}
\end{document}
share|improve this answer
1  
Thanks Andrew, posted to texample.net/tikz/examples/christmas-tree-2 ! Kindly tell me if I should change something. – Stefan Kottwitz Dec 24 '11 at 16:15
@StefanKottwitz Looks great. The only change I'd make would be to put the (star) coordinate at (0,0) - it is at (0,-1) to put it at the right place with respect to the code listing. It just looks a little odd to put it at (0,-1) (but you should check that all the other pieces position correctly - I had quite a time with positioning the original tree). – Andrew Stacey Dec 24 '11 at 18:40

Another tree that can be decorated:

Merry Christmas, everybody!

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
%
\begin{tikzpicture}
\begin{axis}[
    hide axis, clip=false,
    y domain=0:2*pi,
    samples=30,axis equal, view={45}{20}]

\addplot3 [domain=0:4,surf,shader=flat,z buffer=sort,fill=green!50!brown, draw=green!50!black, line join=bevel] 
    ({(1.3*x-floor(x))*x^0.5*cos(deg(y))},
     {(1.3*x-floor(x))*x^0.5*sin(deg(y))},
     {-5*x});

\addplot3 [domain=0:4.5, samples=10, samples y=0, fill=yellow!85!red, draw=yellow!55!red] ({0},{sin(x/5*360) * (1 - x + floor(x)) },{cos(x/5*360) * (1 - x + floor(x) )  + 0.5}) -- cycle;
\end{axis}
\end{tikzpicture}%
%
\end{document}
share|improve this answer
3  
Haha! This is fantastic! Merry Christmas indeed! – user2473 Dec 23 '11 at 1:50
2  
A great idea to use pgfplots for this drawing! – Stefan Kottwitz Dec 24 '11 at 14:46

Here's mine:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{scopes,svg.path,shapes.geometric,shadows}
\begin{document}
\begin{tikzpicture}[
  mystar/.style={star, minimum size=2cm, star point ratio=2.5, shade, thick,
    line join=round, color=yellow!80!black, draw=red!20!black,
    top color=yellow!80!white, bottom color=yellow!60!black},
  mytree/.style={scale=0.5, rotate=180, draw=green!60!black, thick,
    line join=round, inner color=green!60!yellow, outer color=green!50!black},
  myball/.style={shade, ball color=#1, circular drop shadow={
    shadow xshift=0pt, shadow yshift=-.5ex, fill=green!40!black}}
  ]
  {[mytree]
  \shadedraw svg "M355,430
    q90,10 105,-85 30,0 50,-30 20,30 50,30 50,-20 100,0 10,88 105,85
    -45,90 -205,25 Q400,520 355,430";
  \shadedraw svg "M380,325
    q83,10 105,-80 25,0 35,-30 20,25 40,30 20,-10 35,-25 20,20 40,25
    25,90 105,82 -15,50 -120,15 -30,-2 -60,12 -30,0 -52,-28
    C490,370 380,360 380,325";
  \shadedraw svg "M435,225
    q65,-8 90,-70 35,40 70,0 25,60 90,70 -30,52 -90,5 -36,48 -73,-3
    C520,254 445,265 435,225";
  \shadedraw svg "M470,139
    q50,5 90,-80 50,90 90,80 -30,30 -50,20 -40,45 -78,0
    Q500,170 470,139";
  }
  %\shadedraw svg[scale=0.5,rotate=180]
  %"M460,532 q50,-8 q77,-45 v-20 a20,13 0 1 1 48,0 v20 q30,40 77,45";
  %pgf/tikz doesn't like the arc operation, as stated in manual

  \node[mystar] at (-9.85,-1) {$\lambda$};

  \shade[myball=blue]   (-9.7,-2.2)   circle (.2cm);
  \shade[myball=red]    (-9.2,-3.8)   circle (.2cm);
  \shade[myball=green]  (-10.3,-4)    circle (.4cm);
  \shade[myball=yellow] (-8.95,-5.4)  circle (.4cm);
  \shade[myball=red]    (-10.7,-6.1)  circle (.4cm);
  \shade[myball=blue]   (-10.8,-5)    circle (.2cm);
  \shade[myball=yellow] (-9.5,-6.7)   circle (.2cm);
  \shade[myball=green]  (-8.3,-7.6)   circle (.4cm);
  \shade[myball=yellow] (-11.7,-7.6)  circle (.4cm);
  \shade[myball=blue]   (-10.5,-7.8)  circle (.2cm);
\end{tikzpicture}
\end{document}

which looks like:

christmastree

Merry Christmas!

share|improve this answer
4  
So beautiful with only a few lines! – Stefan Kottwitz Dec 24 '11 at 14:50
1  
I am curious—why did you put a lambda inside the star? – Harold Cavendish Dec 24 '11 at 22:50
2  
@Harrold: It was just a small easter egg (for lambda calculus). – morbusg Dec 25 '11 at 8:23
4  
Easter egg at Christmas. Ha ha ha. (Or "ho ho ho") – Andrew Stacey Dec 26 '11 at 18:46
1  
@GarbageCollector: Heh, you are absolutely right. However, I get an error with plain which seems to relate to svgpath. – morbusg Nov 8 '12 at 4:51
show 4 more comments

I have learned a couple of new things in TikZ and created an own minimalistic version loosely based on Altermundus' first creation (and a beautiful one it is). Hopefully he does not mind. Merry Christmas to all of you!

\documentclass[border=2mm]{standalone}
\usepackage[dvipsnames]{xcolor}  
\usepackage{tikz}
\usetikzlibrary{shapes,decorations.shapes}
\newsavebox{\ball}
\savebox{\ball}{ 
\begin{tikzpicture}[scale=.1]
\draw (0,0) -- (0, 5);
\shadedraw[ball color=red] (0,0) circle (60pt);
\end{tikzpicture}
} 
\begin{document}
\begin{tikzpicture} 
   \draw[fill=RawSienna] 
   (-.5,-1)  -- (.5,-1) -- (.5,4) -- (-.5,4) -- (-.5,-1) ;
\draw[fill=green!50!black] 
(-3.5,2) -- (3.5, 2) -- (1.5,4) -- (3, 4) -- (1, 6) -- (2, 6) -- (0,9) -- (-2,6) -- (-1,6) -- (-3,4) -- (-1.5,4) -- (-3.5,2);
\foreach\deco in {(1.5,5.65),(-1.5,5.65),(0.75,7.5),(-0.75,7.5),(-2,3.65), (2,3.65), (2.6,1.65),(-2.6,1.65)}
\node at \deco {\usebox{\ball}} ; 
 \node [star, star point height=.3cm, minimum size=1.2cm, draw,fill=yellow] at (0,9.1) {};
\end{tikzpicture}
\end{document}

Christmas tree.

share|improve this answer

Merry Christmast everyone!

animation

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\usepackage{animate}
\usepackage{hyperref}
\hypersetup{pdfpagemode=FullScreen}
\usepackage{ifthen}
\newcounter{mycount}
\setcounter{mycount}{0}

\begin{document}

\begin{frame}[fragile]{}
\begin{center}
\resizebox{5cm}{!}{%
    \begin{animateinline}[loop, poster = first,controls]{10}
    \whiledo{\themycount<10}{
        \begin{tikzpicture}[ballstyle/.style={circle,draw=blue!50,fill=\c,thick, minimum size=6mm}]
             \pgfmathdeclarerandomlist{color}{{red}{blue}{yellow}{white}{purple}}
             \pgfmathrandomitem{\c}{color}
             \foreach\ycoord in {-3,0,3}{
                \draw[fill=green,draw=green] (-3,\ycoord)--(3,\ycoord)--(0,\ycoord+3)--cycle;
                \node at (3,\ycoord) [ballstyle] {};
                \node at (-3,\ycoord) [ballstyle] {};}
             \node at (0,6) [star,fill =yellow,minimum size=2cm] {};
             \draw[fill=brown,draw=black] (-1,-3)--(1,-3)--(1,-5)--(-1,-5)--cycle;
        \end{tikzpicture}
        \stepcounter{mycount}
        \ifthenelse{\themycount<10}{
                \newframe
        }{
                \end{animateinline}
        }
        }
    }
\end{center}
\end{frame}

\end{document}
share|improve this answer
2  
For slightly more realistic trees you could use the one here: tex.stackexchange.com/a/34676/2693 – Alan Munn Dec 24 '11 at 18:36
@AlanMunn Thanks, I was looking for that post! I was mainly concentrating on the animation. – cmhughes Dec 24 '11 at 18:40
{\let~\catcode~`A0 AgdefAs.#1.{Acsname#1Aendcsname}AdefAq#1#2#3#4#5#6#7#8#9{%#######################
AdefAy##1###1##3##4##5###3###2##8##9{AdefAw####1#####1####3####4####5#####3#####2####8####9{%#######
AdefAz########1#########1########3########4########5#########3#########2########8########9{Aegroup%#
As.d####9cum##5ntc#6##9ss.[11pt]{scr####4tc#6}%#####################################################
As.##3p##9c#4##9g##5.[dv##1psn##9m##5s#8svgn##9m##5s]{xc####9#6####9r}%#############################
As.##3p##9c#4##9g##5.{t##8z}As.##3t##8z#6ibr##9r#9.{%###############################################
sh##9p##5s#8########4##1####9ns.sh##9p##5s#8########4##1####9ns.#5r##9ct##9#6s#8%###################
########4##1####9ns.m####4#4##1ngs#8#########3####9ws}%#############################################
As.n##5ws##9v##5b####9x.{Amycd}%####################################################################
As.s##9v##5b####9x.{Amycd}{#####2###1{####1}[sc##9#6##5=.1]%########################################
Ashade[t####9p#####2c####9#6####9r=#9##5#6#6####9w#8b####9tt####9m#####2c####9#6####9r=r##5d]%######
#####2(####8#8####8###2#########1########1#####3#8.########8#####2########5#####2%##################
#####3#8####3###2#########1#####2(####8#8########8#########1########1#########21#8####3###2%########
#####2########5#####2#########21#8.########8#########1#####2(####8#8####8###2;%#####################
#7[#9##5#6#6####9w!9####8!b#6##9c#4]#####2(.8#8####8###2#####2r##5ct##9ng#6##5#####2%###############
#########2.8#8-5###2;%##############################################################################
###3{####1}#####2}As.t##8zs##5t.{p####5nt/.st#9#6##5={dr##9w=################1!5####8!b#6##9c#4%####
#8#####2#5##1#6#6=################1!5####8}#8%######################################################
m#9#####2st####4/.st#9#6##5={########4##5#8########4##1####9n={sh##9p##5#####2b##9c#4gr####9unds#8%#
sh##9p##5=st####4}#8st####4#####2p####9##1nts=################1}}%##################################
###1{d####9cum##5nt}%###############################################################################
###1{####1}[#####2b##9#6#6#####2r##5d/.st#9#6##5={%#################################################
########4##5#8#####2########4##1####9n={m####4#4##1ngs#8m####4#4=b##5tw##5##5n#####2%###############
p####9s##1t##1####9ns#####2.#1#####2########5#####21#####2st##5p#####23cm%##########################
w##1th#####2{As.pg##4hs##5tm##9cr####9.{Asz}{#1#####2+#####2####3#####2*#####2r########5}%##########
#####1[#########3##1ng=b##9#6#6#8b##9#6#6#####2c####9#6####9r=r##5d]#####2(####8#8####8###2#####2%##
c##1rc#6##5[r##9d##1us=Asz#####2mm];%###############################################################
}}}#####2#8b##9#6#6#####2b#6u##5/.st#9#6##5={########4##5#8########4##1####9n=%#####################
{m####4#4##1ngs#8m####4#4=b##5tw##5##5n#####2p####9s##1t##1####9ns#####2####8.1#####2########5%#####
#####2.9#####2st##5p#####23cm%######################################################################
w##1th#####2{As.pg##4hs##5tm##9cr####9.{Asz}{#1#####2+#####2####3#####2*#####2r########5}%##########
#####1[#########3##1ng=b##9#6#6#8b##9#6#6#####2c####9#6####9r=b#6u##5]#####2%#######################
(####8#8####8###2#####2c##1rc#6##5[r##9d##1us=Asz#####2mm];%########################################
}}}]Adraw[#5##1#6#6=M####4####9####9n#8u#6tr##9#####2th##1c#4]%#####################################
(.#25#8-1###2#####2########3#####2########1(####3#8####3###2#####2########5#####2(%#################
####3#83###2#####2########3#####2(####8####3#84###2%################################################
--#####2#########2####8####3#84###2#####2########3#####2########1#########2####3#83###2#####2%######
########5#####2#########2####3#8####3###2#####2########3#####2#########2.#25#8-1###2#####2;%########
Ashade[u#6tr##9#####2th##1c#4#8#####2t####9p#####2c####9#6####9r=gr##5##5n!9####8!b#6##9c#4#8%######
b####9tt####9m#####2c####9#6####9r=gr##5##5n!1####8!b#6##9c#4]%#####################################
(####8#81####8###2#####2########3########1#####2(####8#88###2#####2########5#####2#####3########9%##
#####2########3#####2#####3####3########9%##########################################################
########3#####2########1#####3########9#####2########5#####2#####3########9#####2########3#####2(%##
####8####3#8#2.#15###2%#############################################################################
########3#####2########1#####3####3#85###2#####2########5#####2(#1####3#84###2#####2########3#####2%
(3#84###2%##########################################################################################
########3#####2########1(#1#84###2#####2########5#####2#####3.#15#84###2#####2########3#####2%######
#####3#84####3###2%#################################################################################
########3#####2########1(#1#8########8#####2########5#####2(3####3#8########8#####2########3#####2(%
4#8########8%#######################################################################################
########3#####2########1#####3#81###2#####2########5#####2#########21#81###2#####2########3#####2%##
#########24#8########8%#############################################################################
########3#####2########1#########23####3#8########8#####2########5#####2#########2#1#8########8%####
#####2########3#####2#########21#84####3###2%#######################################################
########3#####2########1#########21.#15#84###2#####2########5#####2#########2#1#84###2#####2%#######
########3#####2#########23#84###2%##################################################################
########3#####2########1#########2#1####3#84###2#####2########5#####2#########21####3#85###2#####2%#
########3#####2#########2####8####3#8#2.#15###2%####################################################
########3#####2########1#####2#########21########9#####2########5#####2#########21########9#####2%##
########3#####2#########21####3########9%###########################################################
########3#####2########1#####2#########21########9#####2########5#####2(####8#88###2#####2########3%
#####2(####8#81####8###2;%##########################################################################
As.#5####9r##5##9ch.#####2Acd#####2##1n#####2{(#1#85###2#8#########2#1#85###2#8(####8####3#8#2####3%
###2#8#########2####8####3#8#2####3###2#8#########23#8#1####3###2#8#####2(3#8#1####3###2#8%#########
#####3####3#81.#25###2#8#########21####3#81.#25###2}%###############################################
Anode#####2##9t#####2Acd#####2{As.##3b####9x.{Amycd}}#####2;%#######################################
Anode#####2[st####4#8#####2st####4#####2p####9##1nt#####2h##5##1ght=####3cm#8#####2m##1n##1mum%#####
#####2s##1z##5=####3cm#8dr##9w#8#5##1#6#6=#9##5#6#6####9w#8th##1c#4]%###############################
##9t#####2(####8#81####8###2#####2{};###1{sc####9p##5}[########4##1####9n={sh##9p##5#####2s##5p=.#1%
cm#8#####2sh##9p##5#####2s##1z##5=.#15cm}]%#########################################################
Adraw#####2[m#9#####2st####4=#3#8#####2p####5nt=r##5d]#####2#########24#8########8%#################
########3#####2########1(####8#8########8#####2########5#####2#####3#83####3###2#####2########3%####
#####2#####3#84.4####8###2;%########################################################################
Adraw#####2[m#9#####2st####4=#3#8#####2p####5nt=r##5d]#####2#########21####3#85.4####8###2%#########
########3#####2########1(####8#85.4####8###2#####2########5#####2(####8####3#8#3####3###2#####2%####
########3#####2(####8####3########9;%###############################################################
Adraw#####2[m#9#####2st####4=#3#8#####2p####5nt=b#6u##5]#####2(4#8########8%########################
########3#####2########1#####2(####8#8########8#####2########5#####2#########21#83####3###2#####2%##
########3#####2#########21#84.4####8###2;%##########################################################
Adraw#####2[m#9#####2st####4=#3#8#####2p####5nt=b#6u##5]#####2#####3####3#85.4####8###2%############
########3#####2########1(####8#85.4####8###2#####2########5#####2#########2####8####3#8#3####3###2%#
#####2########3#####2#########2####8####3########9;%################################################
###3{sc####9p##5}#####1[b##9#6#6#####2r##5d](####8#81####8###2#####2########3########1#####2(####8%#
#88###2#####2########5#####2#####3########9#####2########3#####2#####3####3########9%###############
########3#####2########1#####3########9#####2########5#####2#####3########9#####2########3#####2(%##
####8####3#8#2.#15###2%#############################################################################
########3#####2########1#####3####3#85###2#####2########5#####2(#1####3#84###2#####2########3#####2%
(3#84###2%##########################################################################################
########3#####2########1(#1#84###2#####2########5#####2#####3.#15#84###2#####2########3#####2#####3%
#84####3###2%#######################################################################################
########3#####2########1(#1#8########8#####2########5#####2(3####3#8########8#####2########3#####2(%
4#8########8%#######################################################################################
########3#####2########1#####3#81###2#####2########5#####2#########21#81###2#####2########3#####2%##
#########24#8########8%#############################################################################
########3#####2########1#########23####3#8########8#####2########5#####2#########2#1#8########8%####
#####2########3#####2#########21#84####3###2%#######################################################
########3#####2########1#########21.#15#84###2#####2########5#####2#########2#1#84###2#####2%#######
########3#####2#########23#84###2%##################################################################
########3#####2########1#########2#1####3#84###2#####2########5#####2#########21####3#85###2#####2%#
########3#####2#########2####8####3#8#2.#15###2%####################################################
########3#####2########1#####2#########21########9#####2########5#####2#########21########9#####2%##
########3#####2#########21####3########9%###########################################################
########3#####2########1#####2#########21########9#####2########5#####2(####8#88###2#####2########3%
#####2(####8#81####8###2;%##########################################################################
#####1[b##9#6#6#####2b#6u##5](####8#81####8###2#####2########3########1#####2(####8#88###2#####2%###
########5#####2#####3########9#####2########3#####2#####3####3########9%############################
########3#####2########1#####3########9#####2########5#####2#####3########9#####2########3#####2(%##
####8####3#8#2.#15###2%#############################################################################
########3#####2########1#####3####3#85###2#####2########5#####2(#1####3#84###2#####2########3#####2%
(3#84###2%##########################################################################################
########3#####2########1(#1#84###2#####2########5#####2#####3.#15#84###2#####2########3#####2#####3%
#84####3###2%#######################################################################################
########3#####2########1(#1#8########8#####2########5#####2(3####3#8########8#####2########3#####2(%
4#8########8%#######################################################################################
########3#####2########1#####3#81###2#####2########5#####2#########21#81###2#####2########3#####2%##
#########24#8########8%#############################################################################
########3#####2########1#########23####3#8########8#####2########5#####2#########2#1#8########8%####
#####2########3#####2#########21#84####3###2%#######################################################
########3#####2########1#########21.#15#84###2#####2########5#####2#########2#1#84###2#####2%#######
########3#####2#########23#84###2%##################################################################
########3#####2########1#########2#1####3#84###2#####2########5#####2#########21####3#85###2#####2%#
########3#####2#########2####8####3#8#2.#15###2%####################################################
########3#####2########1#####2#########21########9#####2########5#####2#########21########9#####2%##
########3#####2#########21####3########9%###########################################################
########3#####2########1#####2#########21########9#####2########5#####2(####8#88###2#####2########3%
#####2(####8#81####8###2;%##########################################################################
As.#5####9r##5##9ch.#####2Ai#####2##1n#####2{####8####3#8####8.#3#8########3.#81.#3}%###############
#7#####2[wh##1t##5!8####8!b#6u##5#8########4##1####9n=K####9ch#####2sn####9w#5#6##9#4##5#8####9p%###
##9c##1t#9=.9]%#####################################################################################
[sh##1#5t={(r########5*5#8rnd*8###2}#8sc##9#6##5=Ai]%###############################################
[d####9ub#6##5#####2c####9p#9#####2#########3####9w={####9p##9c##1t#9=####8.#1#8#########3####9w%###
#####2xsh##1#5t=####8pt#8%##########################################################################
#########3####9w#####2#9sh##1#5t=3*Ai#####2pt#8#5##1#6#6=wh##1t##5#8dr##9w=n####9n##5}]%############
########4##5#####2{########4##5#####2{########4##5#####2{(####8#8####8###2#####2--#####2++(#3####8:%
1###2#####2--#####2++#########2#3####8:1###2#####2--#####2c#9c#6##5%################################
}}};###3{####1}###3{d####9cum##5nt}}Az{#####2c####9ntr####9#6s#####2}{#####2..}{..}{d##5c####9r##9t%
}{##9nd}{sh##9d}{(-}{#1###2}{#8#2###2}}Aw{t##8zp##1ctur##5}Apath{.5}{##9r}{##9##1}{(1}{ }0o}%#######
Ay iAbegin{use}{#5mat}eAend){i#4}a}Aq276kflAfill,y%#################################################
share|improve this answer
8  
Looks like a duplicate :) – dıʞsdoʇ Oct 26 '12 at 9:28
3  
Awesome!!I plan to use this as a showcase as to how easy TeX is to use... – Peter Grill Oct 26 '12 at 16:21
4  
If you look at this code without blinking for 5 minutes, you start to see a christmas tree. :) – Paulo Cereda Oct 27 '12 at 20:57
1  
@AlexG imagine again:-) – David Carlisle Dec 18 '12 at 11:36
1  
No, just a few minutes (if I had taken longer I would have done a better job of getting even line length without using %. I didn't type it in of course it was just derived from Alain's code by applying a few regular-expression replace from his posted code, but they were just interactively applied not any saved script – David Carlisle Dec 18 '12 at 11:53
show 8 more comments

Previous solutions don't really use the fact that the tree can be completely generated procedurally (I think this is what the OP originally intended):

Fractal Christmas Tree

The solution added a new rule to the L-system, that collected some "good" points where decorations might be added. (good points are found on the main branches). From this list values are selected randomly, and baubles or lights are added to these points.

And the picture will change every year :)

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, lindenmayersystems,shapes,decorations,decorations.shapes}
\begin{document}

\def\pointlistleft{}
\def\pointlistright{}
\pgfmathsetseed{\year * 6}
\makeatletter
\pgfdeclarelindenmayersystem{Christmas tree}{
    \symbol{C}{\pgfgettransform{\t} \expandafter\g@addto@macro\expandafter\pointlistleft\expandafter{\expandafter{\t}}}
    \symbol{c}{\pgfgettransform{\t} \expandafter\g@addto@macro\expandafter\pointlistright\expandafter{\expandafter{\t}}}
    \rule{S -> [+++G][---g]TS}
    \rule{G -> +H[-G]CL}
    \rule{H -> -G[+H]CL}
    \rule{g -> +h[-g]cL}
    \rule{h -> -g[+h]cL}
    \rule{T -> TL}
    \rule{L -> [-FFF][+FFF]F}
}
\makeatother

\begin{tikzpicture}[rotate=90]
\draw [color=brown!50!black,line width=2.5pt] (0,0) -- (170pt,0);
\draw [color=green!50!black,l-system={Christmas tree,step=4pt,angle=16,axiom=LLLLLLSLFFF,order=10,randomize angle percent=20}] lindenmayer system -- cycle;

\pgfmathdeclarerandomlist{pointsleft}{\pointlistleft}
\pgfmathdeclarerandomlist{pointsright}{\pointlistright}
\pgfmathdeclarerandomlist{colors}{{red}{blue}{yellow}}

\foreach \i in {0,1,...,5}
{
    \pgfmathrandomitem{\c}{pointsleft}
    \pgfsettransform{\c}
    \pgfgettransformentries{\a}{\b}{\c}{\d}{\xx}{\yy}
    \pgfmathrandomitem{\c}{pointsright}
    \pgfsettransform{\c}
    \pgfgettransformentries{\a}{\b}{\c}{\d}{\XX}{\YY}
    \pgftransformreset

    \pgfmathsetmacro\calcy{min(\yy,\YY)-max((abs(\yy-\YY))/3,25pt)}

    \draw[draw=orange!50!black, fill=orange!50, decorate, decoration={shape backgrounds, shape=star, shape sep=3pt, shape size=4pt}, star points=5] (\xx,\yy) .. controls (\xx,\calcy pt) and (\XX,\calcy pt) .. (\XX,\YY);
}

\foreach \i in {0,1,...,15}
{
    \pgfmathrandomitem{\c}{pointsleft}
    \pgfsettransform{\c}
    \pgftransformresetnontranslations
    \draw[color=black] (0,0) -- (0,-4pt);
    \pgfmathrandomitem{\c}{colors}
    \shadedraw[ball color=\c] (0,-8pt) circle [radius=4pt];
}

\foreach \i in {0,1,...,15}
{
    \pgfmathrandomitem{\c}{pointsright}
    \pgfsettransform{\c}
    \pgftransformresetnontranslations
    \draw[color=black] (0,0) -- (0,-4pt);
    \pgfmathrandomitem{\c}{colors}
    \shadedraw[ball color=\c] (0,-8pt) circle [radius=4pt];
}

\end{tikzpicture}
\end{document}
share|improve this answer

Just a tree

tree

with extremely ugly code(I do not know how to do it corectly?! -ovelay and center):

\documentclass{article}
\usepackage{overpic}
\usepackage{graphicx} 
\begin{document}
\begin{overpic}[unit=1cm, width=8cm, height=12cm]{ttt}
\put(14.5,0){\includegraphics[width=4cm,height=12cm]{ttt}}
\put(23,0){\includegraphics[width=1.5cm,height=12cm]{ttt}}
\end{overpic}
\end{document}

ttt.pdf is the compiled tree from the question.

share|improve this answer
I don't see how this answers the original question. – Werner Feb 9 '12 at 2:16
3  
@werner: It doesn't, and I would never expect it to be accepted as an answer. I consider it to be a contribution never the less. – Hans-Peter E. Kristiansen Feb 9 '12 at 4:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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