Next: , Previous: Introduction by example, Up: Introduction by example



2.1 Hello world

The sketch program above is nearly the simplest one possible, the equivalent of a “hello world” program you might find at the start of a programming language text. If it is saved in the file simple.sk, then the command

  sketch simple.sk -o simple.tex
creates a file simple.tex containing PSTricks commands to draw these objects on paper. The contents of simple.tex look like this.
  \begin{pspicture}(-1,-1)(2,2)
  \pstVerb{1 setlinejoin}
  \psline(-1,-1)(.333,.333)
  \pspolygon[fillstyle=solid,fillcolor=white](0,0)(1,0)(0,1)
  \psline(.333,.333)(2,2)
  \end{pspicture}
The hidden surface algorithm of sketch has split the line into two pieces and ordered the three resulting objects so that the correct portion of the line is hidden.

If you've noticed that the projection we are using seems equivalent to erasing the z-coordinate of the three-dimensional input points, pat yourself on the back. You are correct. This is called a parallel projection. The z-coordinate axis is pointing straight out of the paper at us, while the x- and y-axes point to the right and up as usual.

The resulting picture file can be included in a LaTeX document with \input{simple}. Alternately, adding the command line option -T1 causes the pspicture to be wrapped in a short but complete document, ready to run though LaTeX. In a finished, typeset document, the picture looks like this. (The axes have been added in light gray.)

ex020.png

It is important to know that only the “outside” of a polygon is normally drawn. The outside is where the vertices given in the polygon command appear in counter-clockwise order. Thus, if the command above had been

  polygon(0,1,0)(1,0,0)(0,0,1)
the polygon would not appear in the picture at all. It would have been culled from the scene. This culling behavior may seem strange, but stay tuned.

Footnotes

[1] Or for European users of A4 size paper, -Te.