Eric Weeks - personal pages - graphics techniques

Simple C program to make PostScript pictures

[home] [research]
[software] [pics]
[misc] [about me]

weeks@physics.emory.edu

This describes a program I wrote called "a2ps". I choose this name before I realized there was a different, more well known program by the same name. If you got to this page by mistake looking for that program, try looking here for information about the other a2ps.


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!


Software

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.


About the image:

This is a cellular automata, 100 pixels by 100 pixels, converted to GIF using the method discussed under Sec. 1 above. Click here for more information about this particular CA.

Links...


Current address:
Eric R. Weeks
weeks(circle a)physics.emory.edu
Department of Physics
Emory University
Atlanta, GA 30322-2430