# Can we use a single frame to create the following effect?

I want to create a slide to show how the clipping works as shown in the following animation.

I used two frames, the last frame is needed because I want to hide the unwanted (trimmed) parts of cropped areas of the previous slides. I want to avoid using two frames and repeating the codes.

Can we force beamer to delay the clipping code and hiding the previous painting? I am new to beamer, only knows \pause. :-)

\documentclass{beamer}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}

\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\pspolygon*[linecolor=red](A)(B)(Q)(P)\pause
\pspolygon*[linecolor=green](B)(C)(R)(Q)\pause
\pspolygon*[linecolor=blue](C)(D)(R)\pause
\pspolygon*[linecolor=yellow](D)(A)(P)(R)
\end{pspicture}
\end{frame}

\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}
\pspolygon*[linecolor=red](A)(B)(Q)(P)
\pspolygon*[linecolor=green](B)(C)(R)(Q)
\pspolygon*[linecolor=blue](C)(D)(R)
\pspolygon*[linecolor=yellow](D)(A)(P)(R)
\endpsclip
\end{pspicture}
\end{frame}
\end{document}

-

You can use \only or \onslide; an example with \only:

\documentclass{beamer}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}

\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\only<5>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
\only<1->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
\only<2->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
\only<3->{\pspolygon*[linecolor=blue](C)(D)(R)}
\only<4->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
\only<5>{\endpsclip}
\end{pspicture}
\end{frame}

\end{document}


Edit: After getting a multipe-page PDF, we can also make use of it to create a PDF animation, a GIF animation and PNG images. TeX the following with pdflatex --shell-escape. ImageMagick must be installed in your computer.

\documentclass[preview,border=0pt]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{dummy.tex}
\documentclass[serif]{beamer}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}
\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\only<5>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
\only<1->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
\only<2->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
\only<3->{\pspolygon*[linecolor=blue](C)(D)(R)}
\only<4->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
\only<5>{\endpsclip}
\end{pspicture}
\end{frame}
\end{document}
\end{filecontents*}

\usepackage{animate}

\begin{document}

% create PDF
\immediate\write18{latex dummy}
\immediate\write18{dvips dummy}
\immediate\write18{ps2pdf dummy.ps}

% convert to GIF animation
\immediate\write18{convert -delay 100 -loop 0 -density 200 -alpha remove dummy.pdf \jobname.gif}

% convert to PNG
\makeatletter
\immediate\write18{convert -density 200 -alpha remove dummy.pdf \jobname-\@percentchar02d.png}
\makeatother

% create PDF animation
\begin{preview}
\animategraphics[controls]{2}{dummy}{}{}
\end{preview}
\end{document}

-
@HiggsBoson thank you very much! Animation added! –  Gonzalo Medina Jul 27 '12 at 19:13
For those who want to make use of the produced multiple-page PDF to create a PDF animation, a GIF animation and PNG images, please see the last edit. –  stalking is prohibited Jul 29 '12 at 11:14
Which is the most appropriate among \uncover, \only, \onslide, etc for my problem above? –  stalking is prohibited Oct 18 '12 at 9:48
Why cannot your first code be compiled now while it worked several times ago? –  stalking is prohibited Jul 22 at 8:19

You could use TikZ, which is reasonably well integrated with Beamer already, and do something like:

\begin{frame}
\begin{tikzpicture}
\clip<5> (3,3) circle (3);
\node [coordinate] (A) at (0,0) {};
\node [coordinate] (B) at (6,0) {};
\node [coordinate] (C) at (6,6) {};
\node [coordinate] (D) at (0,6) {};
\node [coordinate] (P) at (1,1) {};
\node [coordinate] (Q) at (5,1) {};
\node [coordinate] (R) at (3,5) {};
\fill<1-> [red] (A) -- (B) -- (Q) -- (P) -- cycle;
\fill<2-> [green] (B) -- (C) -- (R) -- (Q) -- cycle;
\fill<3-> [blue] (C) -- (D) -- (R) -- cycle;
\fill<4-> [yellow] (D) -- (A) -- (P) -- (R) -- cycle;
\end{tikzpicture}
\end{frame}


Result:

-
The first slide is wrong; the red trapezoid "jumps". –  Gonzalo Medina Jul 27 '12 at 22:37
@GonzaloMedina: The first canvas might have different dimension as TikZ provides the smallest but enough canvas automatically. Specifying the canvas dimension in advance will solve this issue. –  stalking is prohibited Jul 28 '12 at 5:46