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.

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

enter image description here

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{pstricks-add}
\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}
share|improve this question

2 Answers 2

up vote 11 down vote accepted

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

\documentclass{beamer}
\usepackage{pstricks-add}
\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}

enter image description here

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{pstricks-add}
\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}
share|improve this answer
1  
@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. –  In PSTricks we trust Jul 29 '12 at 11:14
    
Which is the most appropriate among \uncover, \only, \onslide, etc for my problem above? –  In PSTricks we trust Oct 18 '12 at 9:48
    
Why cannot your first code be compiled now while it worked several times ago? –  In PSTricks we trust 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: Solution with Beamer/TikZ

share|improve this answer
    
The first slide is wrong; the red trapezoid "jumps". –  Gonzalo Medina Jul 27 '12 at 22:37
1  
@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. –  In PSTricks we trust Jul 28 '12 at 5:46

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.