Example: Birthday cake

Published 2012-02-26 | Author: Andrew Stacey

A birthday cake drawing, posted as answer to the question How can I draw a cake using TikZ of N.N.

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% A birthday cake
% Andrew Stacey
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}
-- ++(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)
\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]
start angle=-180, end angle=0] -- ++(0,2) arc[x radius=5pt,
y radius=2.5pt, start angle=0, end angle=-180] -- cycle;
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}