Eric Weeks
- personal pages - graphics
techniquesSimple C program to make PostScript pictures |
weeks@physics.emory.edu |
This method evolved out of a program I got from Tom Solomon. If you have a program which creates black and white data on grid points, such as a cellular automata, I have written a program which can convert this into a PostScript format. That is, rather than plotting it on the screen you can create a PostScript file. This is useful if you don't want to deal with graphics drivers and X-windows commands and all sorts of hassles that I don't know anything about, as I use this method instead.
The program is called a2ps
, which evolved from
mat2las
which Tom Solomon originally wrote. Your
picture-making program produces output which is piped through this
program:
yourprogram | a2ps > picture.ps
The input to a2ps
should start with two numbers: the number
of pixels wide the picture will be, and the height (ie., X and Y
dimensions). Then should follow integers between 0 and 255
corresponding to the color value of each pixel, scanning the picture
from top to bottom, left to right (ie., each row is specified from left
to right, top row is specified first). 255 corresponds to WHITE (no ink
printed on page) and 0 corresponds to black. Intermediate values will
be grey-scaled.
Another way to run the program:
yourprogram > output.dat
a2ps output.dat > output.ps
Note that "a2ps -h
" will display a list of options. You can
do whatever you would like with the source code, except that my name
should remain attached to it (and your name too if you make
modifications). If you have any questions let me know by email;
my email address is at the bottom of the page.
I hope you find this useful!
Click here
to get the source code for a2ps
. This program is written
in C; to compile use cc -o a2ps a2ps.c
Why is this method good? It's easy to convert existing programs to produce the required output, and it's quick. Why is it bad? You need to use a printer or a postscript viewer (like gs) to see your picture. I originally wrote this program when I was at the Santa Fe Complex Systems Summer School and the Cellular Automata research group needed something to display CA's with in a hurry.
NOTE: I have also written a program that takes the same input, but produces PPM output rather than PostScript output. See the next section.