title: Smooth PostScript animations
body: <p>I would like to run animations in PostScript smoothly. To see what I want, let me switch to PostScript directly. Call ghostscript, and</p>
  
  <pre><code>200 dup scale .5 setgray 0 0 3 3 rectfill
  </code></pre>
  
  <p>We have now a gray square.</p>
  
  <pre><code>0 setgray 0 1 3 1 rectfill
  </code></pre>
  
  <p>With a black stripe in it.  We will now fill that stripe, one time white
  and black in succession:</p>
  
  <pre><code>{1 setgray 0 1 3 1 rectfill 0 setgray 0 1 3 1 rectfill} loop
  </code></pre>
  
  <p>You will see now some flickering of black and white rectangles that
  are smaller than the original black stripe.  Ideally, we would see
  the original grey square. Or almost.  Where can I get such functionality today?</p>
  
  <p>To see a more interesting animation sequence searching for magic
  squares of size 5:</p>
  
  <pre><code>wget http://www.complang.tuwien.ac.at/ulrich/gupu/l5.eps.gz
  zcat l5.eps.gz | ghostscript -
  </code></pre>
  
  <p>A couple of years ago I did try to address these issues.  But it never went into ghostscript or Xfree. See
  <a href="http://www.complang.tuwien.ac.at/ulrich/gs-db" rel="noreferrer">this page</a>.  Maybe there are some better ideas now?</p>
  
  <p>Edit: After reading the responses so far, let me clarify one issue here. Essentially, there are two independent issues in this question:</p>
  
  <ul>
  <li><p>How should an animation be viewed from the language level? I believe, the best way is to view each frame as a single page. With <code>copypage</code> incremental changes can be realized with low effort. Sadly, that semantics of <code>copypage</code> is only present in Level 1 and 2.  In Level 3, the meaning of <code>copypage</code> changed to <code>showpage</code>. I did - many years ago - a <a href="http://www.complang.tuwien.ac.at/ulrich/gs-db" rel="noreferrer">little modification to ghostscript</a> to delay all visible changes up to <code>copypage</code> or <code>showpage</code>. In this manner, a single <code>XCopyArea</code> containing the changed area is performed <strong>locally</strong> on the server (that is, the display).</p></li>
  <li><p>How should actual changes on the visual display be synchronized to avoid artefacts that where not present in the graphics described? The irregular flicker you see is not a privilege of PostScript, it seems to be present in any double-buffered system I have seen so far. Just try to program this in whatever system you see fit.</p></li>
  </ul>
  
  <p>Further edit:</p>
  
  <p>To get the right language level, that is level 1 or 2 do (for ghostscript):</p>
  
  <pre><code>systemdict /.setlanguagelevel known {2 .setlanguagelevel} if
  </code></pre>
  
  <hr>
  
  <p>Edit: I am adding this comment to may attract some new <a href="/questions/tagged/postscript" class="post-tag" title="show questions tagged 'postscript'" rel="tag">postscript</a> contributors.</p>