CSC 195 2014S, Class 04: PostScript
===================================

_Overview_

* Preliminaries.
    * Admin.
    * Experiences with Processing.
* PostScript basics.
* Important drawing commands.
* Program control.
* Sample procedures.
* Why study PostScript?
* Lab.

Preliminaries
-------------

### Admin

* I need to leave at 8:35 today for an optometrist's appointment.
* Most of the live examples from today are in the examples/postscript
  folder.
* Assignment 4: Getting Started with Postscript is not yet available.
    * Skim/read the PostScript Tutorial
      <http://partners.adobe.com/public/developer/ps/sdk/sample/index_psbooks.html>
    * Get a copy of the PostScript reference manual
      <http://www.adobe.com/products/postscript/pdfs/PLRM.pdf>  
    * Write a PostScript procedure to draw a star.
    * Write another interesting PostScript procedure.

### What you learned about Processing ...

* It's really cool because ... you can learn about where the mouse
  pointer is and use that to affect lots of different things: colors,
  other positions, etc.
    * It an also be a trigger/catalyst
* You can set the frame rate to make things faster/slower.
    * But if your code is slow, the frame rate may screw up
* It's pretty easy to make cool stuff
    * A lot of built in things
    * Straightforward language
* Nice hybrid things available - Square/rectangle vs. four lines
    * Our moral: Primer challenges them to build, but we provide
   
PostScript basics
-----------------

* Language for describing documents to printers.
* 1982!  Still used today!
* We think of documents as markup - PostScript is a Turing-complete
  programming language
    * Stack based!
    * operand operand operation
* Vector graphics
* In MathLAN
    * Preview with ghostview
    * Convert to pdf with ps2pdf
* Three books
    * Red Book - Reference manual
    * Green Book - Tutorial and Cookbook
    * Blue Book - Program design

Important drawing commands
--------------------------

Program control
---------------

Sample procedures
-----------------

Sample Code
-----------

### How Sam Draws Rectangles

    % left bottom width height rect
    %   Draw the specified rectangle.
    /rect {     % l b w h
      4 2 roll  % w h l b
      moveto    % w h
      1 index   % w h w
      0         % w h w 0
      rlineto   % w h
      dup       % w h h
      0 exch    % w h 0 h
      rlineto   % w h
      exch      % h w
      neg 0     % h -w 0
      rlineto   % h
      neg       % -h
      0 exch    % 0 -h
      rlineto   % 
      stroke    % 
    } def

### Right-justifying text

    % string showright
    /showright {    % str 
      dup           % str str
      stringwidth   % str str-width str-height
      pop           % str str-width
      neg           % str -str-width
      0             % str -str-width 0
      rmoveto       % str 
      show
    } def

Why study PostScript?
---------------------

Lab
---

* Set a (simple) goal for your neighbor.
* Achieve the goal your neighbor set for you.

or

* Just play

or

* Read the first few pages of the PostScript tutorial
