# use tikz to draw a rectangle enclosed by an oval

I use the code below to draw a rectangle enclosed by a oval, however it doesn't work.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}

\usepackage{fp}

% parameterized tikz graphics
\newcommand{\intersect}[1]{%
\def\setA{(0,0) circle (1)}%
\def\setc{(1,0) ellipse (1,2)}%
\def\setB{(#1,0) circle (1)}%
% define the bounding box
\def\boundb{(-2,2) rectangle (4,-2)}%
%
\begin{tikzpicture}
\draw \boundb;
% intersection
\begin{scope}
\clip \setc;
\end{scope}
\begin{scope}[even odd rule]% first circle without the second
\clip \setB \boundb;
\end{scope}
\draw \setc;
\end{tikzpicture}
}

\begin{document}
\begin{frame}
\begin{center}

\begin{animateinline}[autoplay,palindrome]{12}
%first frame, xb=0.0
\gdef\xb{0}% xb initial value
\intersect{\xb}%
%remaining frames, xb=0.1...2.1
\whiledo{\lengthtest{\xb pt < 2.1pt}}{%
\newframe
\FPeval{xb}{\xb+0.1}% new xb
\xdef\xb{\xb}% make \xb global
\intersect{\xb}%
}%
\end{animateinline}

\end{center}
\end{frame}
\end{document}

-
can you add a figure to explain –  rpapa Jul 28 '12 at 12:27
OK, I have added it. –  sweetyBaby Jul 28 '12 at 12:32
for ellipses use \def\setc{(1,0) ellipse (1 and 2), so and instead of , –  Tom Bombadil Jul 28 '12 at 12:53
@TomBombadil Even (1,0) circle (1 and 2) works. –  percusse Jul 28 '12 at 13:09
@percusse: I know, I usually use circle, that's one less character than ellipse ;) –  Tom Bombadil Jul 28 '12 at 15:47

I don't understand what exactly you want to do but the following is working without any problems in Adobe Reader.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}

\begin{document}
\begin{frame}{title}
\begin{animateinline}[autoplay,
palindrome,
begin={
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle (5cm,4cm);
},
end={\end{tikzpicture}}
]{10}
\multiframe{20}{nstep=0.0+0.1}{%
\draw (0.5cm,0.5cm) rectangle (4.5cm,3.5);
\draw (2.5cm,2cm) circle (\nstep cm and 0.8*\nstep cm);
}
\end{animateinline}
\end{frame}
\end{document}


Note that the variable names should start with i,n,d etc. (see the animate manual p.4) to reflect the type of the variable.

-