Writing PostScript files

From Processing

Jump to: navigation, search
Versions: 1.0+
Contributors: watz
Started: 2006-02-18


Adobe PostScript is a page description language which can easily be used to provide a format for saving vector graphics from Processing. To understand how PostScript works, take a look at Zach Lieberman's introduction (see the heading PostScript .) Peter Weingarter has written a very useful PostScript tutorial. Download it as a ZIP file or read it online.

SimplePostscript is a simple library for writing PostScript files. We will use it here to write PostScript files. In an ideal world, SimplePostscript would be an extension of the PGraphics class, but for now it is separate from the built-in Processing graphics commands.

Source Code

/**
ps taken from http://wiki.processing.org/index.php?title=Writing_PostScript_files
@author Marius Watz
*/
 
import SimplePostscript.*;
 
SimplePostscript ps;
 
void setup() {
  size(200,200);
  noLoop();
}
 
void draw() {
  background(100,0,0);
  ps=new SimplePostscript(this);
  ps.open("test.ps",0,0, 300,300);
 
  // Grayscale colors are float values in the 0..1 range
  ps.setgray(0.5f);
  ps.moveto(0,0);
  ps.lineto(300,300);
  ps.stroke();
 
  // RGB colors are integers in the 0..255 range
  ps.setrgb(255,200,0);
  ps.circle(0,50, 30);
  ps.fill();
 
  // CMYK colors are float values in the 0..1 range
  ps.setcmyk(1,0,0,0);
  ps.setfont("Arial",12);
  ps.text(0,100, "Testing text");
  ps.fill();
 
  ps.setcmyk(0,1,1,0);
  ps.setlinewidth(3);
  ps.moveto(0,200);
  ps.curveto(50,100, 100,100, 150,200);
  ps.curveto(200,300, 200,50, 300,0);
  ps.stroke();
 
  // Close file when done. If not closed, file output may not
  // be complete.
  ps.close();
}

Downloads

Related Links

Personal tools