VeryDOC Website, Convert documents
Partners Contact US Site Map
A professional PDF Converter, PDF Writer, PDF Creator, PDF Editor, HTML Converter, Postscript Converter, AutoCAD DWG Converter, as well as PCL Converter, etc.  

How to do simple PostScript commands - Part II

How to do simple PostScript commands - Part I
 

Circles and Arcs

To draw a circle or an arc, use the "arc" command. You must specify the center, radius, and starting and ending angles (in degrees). Also, if you are drawing a circle, you should end with "closepath" in order to join the two ends of the arc. This becomes more important when you're filling the circles but it's a good habit to get into.

So, a typical circle command looks like:

4 5 3 0 360 arc closepath stroke

which puts a circle at the coordinates (4,5) with a radius of 3. As usual, nothing is actually drawn until you say "stroke".

As with drawing straight lines, the command "setgray" changes the color of the line drawn and the command "setlinewidth" will affect the width of the line. The actual code that generated the above picture was:

0 setgray 0.1 setlinewidth 4 5 3 0 360 arc closepath stroke


To make arcs, just change the starting and ending angles:

4 5 3 0 360 arc closepath stroke 5 4 2 0 120 arc closepath stroke


There is also a command "arcn" which draws arcs in the opposite direction; for example, the above arc commands could have been written:

4 5 3 360 0 arcn closepath stroke 5 4 2 120 0 arcn closepath stroke

This is only useful when you want to fill the circles.

Filling shapes

If you have a shape (circle, arbitrary polygon) which you have drawn and closed with "closepath" you can fill the shape. Thus:

4 5 3 0 360 arc closepath 0.7 setgray fill

One side affect of the fill command is that it forgets the current path, as if you had used the "newpath" command. This is the same behavior as "stroke". If you want to fill a shape and also show it's outline, you need to save the current path before you fill it, and then restore the path to draw it (show the outline). You do this with the commands "gsave" and "grestore". They essentially save the entire current PostScript state, and then restore it. Your code will then look like:

0 setgray 0.1 setlinewidth 4 5 3 0 360 arc closepath gsave 0.7 setgray fill grestore stroke

Note that the final stroke command will be black; the color is temporarily changed to light gray, but then "grestore" restores the old color.

Advanced Filling

Suppose you want to fill a shape with a hole in it (like a donut). You have to be careful about the direction you draw the lines in. The outside line would be drawn in a counter-clockwise direction, and the inside line is drawn in a clockwise direction. Generally I don't remember this rule; I just try it both ways until it works. (In order to draw circles in the clockwise direction, use the "arcn" command discussed above).

4 5 3 0 360 arc closepath 4 5 2 360 0 arcn closepath 0.7 setgray fill

Using everything

%!PS-Adobe-1.0

matrix currentmatrix /originmat exch def
/umatrix {originmat matrix concatmatrix setmatrix} def
[28.3465 0 0 28.3465 10.5 100.0] umatrix

0 setgray
0.2 setlinewidth

% head
4 5 3 0 360 arc closepath
stroke

% mouth
4 5 2 210 330 arc closepath
gsave
% this is red:
1 0 0 setrgbcolor fill
grestore
stroke

% eyes
3 6 0.8 0 360 arc closepath
gsave
% this is blue:
0 0 1 setrgbcolor fill
grestore
stroke
5 6 0.8 0 360 arc closepath
gsave
% this is blue:
0 0 1 setrgbcolor fill
grestore
stroke

showpage

 
Relative Products:
HTMLPrint Command Line: Batch print HTML, MHTML and web pages to Windows Printer.
HTML to PDF Converter: Convert HTML files and URLs to PDF, PS, EPS, TIFF, JPEG, PNG, BMP, TGA, etc. files.
DocConverter COM: Convert HTML files and URLs to PDF files by PDFcamp Printer.
docPrint Pro: Batch Convert any printable documents to PDF, PS, EPS, WMF, EMF, TIFF, JPEG, PNG, BMP, etc. files.
HTML to Image Converter: Convert HTML files to JPEG, TIFF, BMP, PNG, WMF, EMF files.
View All VeryPDF Products...
 
See Also:
PDF to Image Converter :: PDF Extract TIFF :: HTML Converter :: PDFcamp Printer :: DocConverter COM :: PDF to Word Converter :: PDF to Text Converter :: Image to PDF Converter :: Image to PDF OCR :: PDF to HTML Converter :: AutoCAD DWG and DXF to PDF Converter :: PCL to PDF Converter :: Document Printer (docPrint) :: VeryPDF PDF Editor :: PDF Password Remover :: Encrypt PDF :: PDF Split-Merge :: PDF Stamper :: VeryPDF PDFPrint :: Advanced PDF Tools :: PDF Editor Toolkit :: Text to PDF Converter :: PowerPoint to Flash :: PowerPoint Converter

Home | Site Map | VeryPDF.com | VeryPCL.com | Contact
Copyright © 2002- VeryDOC.com Company. All Rights Reserved.