Take the 2-minute tour ×
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.

It is always someone's birthday. I would like to use TikZ to draw a birthday cake. There are all sorts of cakes. What I would like is a cake that looks nice and tasty. Preferably a cake with lots of chocolate and vanilla custard. How can I draw this with TikZ?

Here is something to start with:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{shapes}

\newsavebox{\mycandle}% From http://tex.stackexchange.com/a/39211/5701
\savebox{\mycandle}{ 
\begin{tikzpicture}[scale=.1]
  \shade[top color=yellow,bottom color=red] (0,0) .. controls (1,.15)
  and (1,.3) .. (0,2.5) .. controls (-1,.3) and (-1,.15) .. (0,0);
  \fill[red!70!blue] (.4,0) rectangle (-.4,-5);
\end{tikzpicture} }

\begin{document}

\begin{tikzpicture}[>=stealth, shape aspect=.5]
  \draw[fill=yellow!16] (0,-0.2) circle [x radius=1.59cm, y radius=0.29cm];
  \node [cylinder,cylinder uses custom fill, cylinder end fill=yellow!6,
cylinder body fill=yellow!12, shape border rotate=90, minimum width=3cm, minimum
  height=1.2cm, aspect=2.5, overlay, draw] {};
  \foreach \candle in {(-0.32,1.05), (0.32,1.05), (1.2,0.9), (-1.2,0.9), (0.65,0.7), (-0.65,0.7)} \node at \candle {\usebox{\mycandle}};
\end{tikzpicture}

\end{document}

A cake to decorate

Oh, and apparently someone already made a pink cake but without providing a recipe.

share|improve this question
    
I would start calling it as a birthday KX where X as in LaTeX. –  percusse Jan 28 '12 at 16:43
    
There has been a community blog post about this question, see tex.blogoverflow.com/2012/01/the-cake-is-a-lie. –  N.N. Feb 1 '12 at 9:04
add comment

2 Answers 2

up vote 34 down vote accepted

I'm not sure that this will win any prizes for elegance ...

This is the pink cake referred to in the question:

Pink cake drawn with TikZ

And here's the recipe:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\fill[white!80!black] (3,-.2) circle[x radius=5.05,y radius=1.66666];
\fill[white!80!black] (3,0) circle[x radius=5,y radius=1.66666];
\draw[white!75!black] (3,0) circle[x radius=5,y radius=1.66666];
\fill[white!75!black] (3,0) circle[x radius=4,y radius=1.33333];
\begin{scope}
\clip (0,0) arc[x radius=3,y radius=1,start angle=180,delta angle=180] -- ++(0,2)  arc[x radius=3,y radius=1,start angle=0,delta angle=-180] -- ++(0,-2);
\foreach \k in {0,...,60} {
  \pgfmathparse{Mod(\k,2) ? "pink" : "purple!50"}
  \let\linecol=\pgfmathresult
  \draw[line width=1mm,\linecol] (\k mm,2) -- ++(0,-3);
}
\end{scope}
\fill[opacity=.3] (0,2) arc[x radius=3,y radius=1,start angle=180,delta angle=180] -- ++(0,-.5)  arc[x radius=3,y radius=1.25,start angle=0,delta angle=-180] -- ++(0,.5);
\fill[pink] (-.25,2) .. controls +(0,-.5) and +(-2,0) .. ++(3.25,-1.25) .. controls +(2,0) and +(0,-.5) .. ++(3.25,1.25) -- ++(0,1) .. controls +(0,.5) and +(2,0) .. ++(-3.25,1.25) .. controls +(-2,0) and +(0,.5) .. ++(-3.25,-1.25);
\draw[pink!80!black] (-.25,3) .. controls +(0,-.5) and +(-2,0) .. ++(3.25,-1.25) .. controls +(2,0) and +(0,-.5) .. ++(3.25,1.25)  .. controls +(0,.5) and +(2,0) .. ++(-3.25,1.25) .. controls +(-2,0) and +(0,.5) .. ++(-3.25,-1.25);
\fill[pink!80!black] (.75,3) .. controls +(0,-.25) and +(-2,0) .. ++(2.25,-.75) .. controls +(2,0) and +(0,-.25) .. ++(2.25,.75)  .. controls +(0,.25) and +(2,0) .. ++(-2.25,.75) .. controls +(-2,0) and +(0,.25) .. ++(-2.25,-.75);
\foreach \i in {0,...,5} {
\pgfmathsetmacro{\yshift}{-\i * (5 - \i) * .07cm}
\begin{scope}[xshift=\i * .5cm,yshift = \yshift]
\fill[purple!70] (1.5,3) arc[x radius=5pt, y radius=2.5pt, start angle=-180, end angle=0] -- ++(0,2) arc[x radius=5pt, y radius=2.5pt, start angle=0, end angle=-180] -- cycle;
\fill[pink] (1.5,5) arc[x radius=5pt, y radius=2.5pt, start angle=-180, end angle=180];
\fill[yellow] (1.5,7.5) ++(5pt,0) .. controls +(0,-1) and +(.5,0) .. ++(0,-2.5) .. controls +(-.5,0) and +(0,-1) .. ++(0,2.5);
\end{scope}
}
\end{tikzpicture}
\end{document}
share|improve this answer
1  
Fantastic code, Andrew! :) –  Paulo Cereda Jan 29 '12 at 9:47
    
Great recipe! I posted it in the TikZ example gallery. –  Stefan Kottwitz Feb 25 '12 at 23:26
add comment

Here's another cake :)

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,svg.path,shadows,shadings,patterns}
\begin{document}
\pgfdeclarehorizontalshading{candle}
  {4cm}{rgb(0cm)=(.9,.9,.9); rgb(2cm)=(1,1,1); rgb(4cm)=(.9,.9,.9)}
\tikzpicture[
  cake/.style={text=white, draw=white, ultra thick,
    outer color=black!5, inner color=white},
  decoration={markings,mark=between positions 0 and 1 step 1cm with {\shade[
    pattern=crosshatch dots, pattern color=red!80!black, ball color=red,
    xscale=-.8, path fading=south] (0,0) circle (.3);}}]

  \shadedraw[cake,draw=black!40,rotate=180]
    % "artsy" perspective skew
    svg "M24,150 l-10,-70 c10,-50 150,-50 160,0 l-10,70 c-10,35 -130,35 -140,0"
    node {the cake is a lie};
  \shadedraw[cake] (-3.3,-2.8) ellipse (2.7 and 1.25);
  \path[postaction={decorate}] (-3.3,-2.5) ellipse (2 and .7);
  \fill[shading=candle] (-3.5,-2.6) to[bend right] ++(.5,0)
    -- ++(0,2) to[bend right] ++(-.5,0) --cycle;
  \fill[outer color=transparent!0, inner color=orange] (-3.25,-.3) circle (.25);
\endtikzpicture
\end{document}

cake

share|improve this answer
2  
Oh no, the cake is a lie! :) Awesome code! –  Paulo Cereda Jan 30 '12 at 13:43
    
@Paulo: thanks :) I just noticed that to make the candle light prettier, one could change its \fill into a \shade. –  morbusg Feb 3 '12 at 11:34
add comment

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.