# torus to coffee mug homotopy

Does anyone have a TikZ solution to animate the coffee mug --> donut homotopy? • See the following: How to draw a coffee cup – Werner Nov 3 '14 at 0:01
• ah! thanks! if you post as the answer i'll accept it.. or I guess it's just a repost. I couldn't find it because of the difference in search terms.. – rhl Nov 3 '14 at 0:06
• Hi, actually after quickly reviewing that, while the heart of the question is answered, it's really not the same question. Notice that the solution given (which was actually not the answer to the question in that post), is a 2D solution. I'm really looking for the analogue of the above image, which is in 3D.. – rhl Nov 3 '14 at 0:08
• The transformation, expected by OP,is different than already done in How to draw a coffee cup. Hence I am voting for reopening. – Przemysław Scherwentke Nov 3 '14 at 1:19

Taken directly from How to draw a coffee cup:

How about a cut that actually transforms into a donut (more or less smoothely)?

## Code

\documentclass[tikz, border=2mm]{standalone}

\begin{document}

\foreach \x in {0,...,10}
{   \begin{tikzpicture}
\shade[left color=gray!80, right color=gray!30] (-2,0-\x*0.04) -- (-2,-4+\x*0.04) arc (180:360:2 and 0.5) -- (2,0-\x*0.04) arc (360:180:2 and 0.5);
\shade[left color=gray!60, right color=gray!20,even odd rule] (0,0-\x*0.04) circle (2 and 0.5) (0,0-\x*0.04) circle (1.8+\x*0.02 and 0.45+\x*0.005);
\shade[left color=gray!30, right color=gray!80] (0,0-\x*0.04) circle (1.8+\x*0.02 and 0.45+\x*0.005);
\begin{scope}
\clip (2,-0.4) arc (90:270:0.05-\x*0.005 and 0.2) arc (90:-90:0.6 and 1.2) arc (90:270:0.05-\x*0.005 and 0.2) arc (-90:90:0.8 and 1.6);
\fill[inner color=white, outer color=gray!60] (2,-2) circle (0.8 and 1.6);
\end{scope}
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}

\foreach \x in {0,...,10}
{   \begin{tikzpicture}
\shade[left color=gray!80, right color=gray!30] (-2+\x*0.36,-0.4) -- (-2+\x*0.36,-3.6) arc (180:360:2-\x*0.18 and 0.5-\x*0.05) -- (2,-0.4) arc (360:180:2-\x*0.18 and 0.5-\x*0.05);
\shade[left color=gray!30, right color=gray!80] (0+\x*0.18,-0.4) circle (2-\x*0.18 and 0.5-\x*0.05);
\begin{scope}
\clip (2,-0.4) -- ++(0,-0.4) arc (90:-90:0.6 and 1.2) -- ++(0,-0.4) arc (-90:90:0.8 and 1.6);
\fill[inner color=white, outer color=gray!60] (2,-2) circle (0.8 and 1.6);
\end{scope}
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}

\foreach \x in {0,...,10}
{   \begin{tikzpicture}
\begin{scope}
\clip (2,-0.4) -- ++(-0.4+\x*0.04,0) arc (90:270:\x*0.08 and 1.6) -| ++(0.4-\x*0.04,0.4) arc (270:90:\x*0.06 and 1.2);
\fill[inner color=white, outer color=gray!60] (1.2,-0.4) rectangle ++(1.6,-3.2);
\end{scope}
\begin{scope}
\clip (2,-0.4) -- ++(0,-0.4) arc (90:-90:0.6 and 1.2) -- ++(0,-0.4) arc (-90:90:0.8 and 1.6);
\fill[inner color=white, outer color=gray!60] (2,-2) circle (0.8 and 1.6);
\end{scope}
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}

\foreach \x in {0,...,10}
{   \begin{tikzpicture}
\fill[inner color=white, outer color=gray!60,even odd rule] (2-\x*0.16,-2) circle (0.8+\x*0.16 and 1.6) (2-\x*0.16,-2) circle (0.6+\x*0.09 and 1.2-\x*0.02);
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}

\end{document}


## Output • i'm going to try to improve this one to a 3D solution.. – rhl Nov 3 '14 at 0:10
• The linked "duplicate" is far enough from the original question and the answer also doesn't really pertain to the duplicate, so I posted a CW answer. – Werner Nov 3 '14 at 0:10
• agreed. I'll accept shortly, I just want to try and improve this solution... – rhl Nov 3 '14 at 0:14
• Hi, I would also like to reopen on the basis that this isn't really a duplicate and the proposed solution is not equivalent to what I am asking for.. – rhl Nov 3 '14 at 1:36
• @rhl: Let me know once you have a 3D alternative and I'll remove my post. – Werner Nov 3 '14 at 5:40