> back to SimplePostscript
// PStest.pde
// Sample application demonstrating use of the
// SimplePostscript class to output Postscript.
//
// http://processing.unlekker.net/SimplePostscript/

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();
}

		
// PScoordtest.pde
import SimplePostscript.*;

SimplePostscript ps;

void setup() {
  size(200,200);
  ps=new SimplePostscript(this);
  ps.open("coordtest.ps");
  noLoop();
  noFill();
}

void draw() {
  background(255);
  stroke(0);
  ps.setlinewidth(0.25);
  ps.setgray(0);
  int step=20;

  ps.rect(0,0, width,height);
  ps.stroke();

  ellipseMode(CENTER);
  rectMode(CENTER);
  ps.rect(100,100,50,50);

  for(float y=0; y<height+step; y+=step) {
    ellipse(width/2,y, 10+(y+1)/10,10f);
    ps.ellipse(width/2,y, 10+(y+1)/10,10f);
    ps.stroke();
  }

  for(int i=1; i<10; i++) {
    ellipse(width/2,height/2, 10*i,i*10);
    ps.ellipse(width/2,height/2, 10*i,i*10);
    ps.stroke();
  }

  ellipseMode(CORNER);
  ps.ellipse(0,0,20,20);
  ellipse(0,0,20,20);
  ps.stroke();

  ellipseMode(CORNERS);
  ps.ellipse(20,0,40,20);
  ellipse(20,0,40,20);
  ps.stroke();

  ps.close();
}
// PSpattern.pde
// Excample by Toxi - http://www.toxi.co.uk/


import SimplePostscript.*;

SimplePostscript ps;

void setup() {
  size(200,200);
  ps=new SimplePostscript(this);
  ps.open("pattern.ps",0,0, 200,200);
  noLoop();
}

void draw() {
  background(255);
  stroke(0);
  ps.setlinewidth(0.25);
  ps.setgray(0);
  int step=2;
  for(int y=0; y<height; y+=step) {
    beginShape(LINE_STRIP);
    for(int x=0; x<width; x+=step/2) {
      float z=y+calc(x,y);
      vertex(x,z);
      if (x==0) ps.moveto(x,z);
      else ps.lineto(x,z);
    }
    endShape();
    ps.stroke();
  }
  ps.close();
}

float calc(float x,float y) {
  return 10*(sin(x*0.1)*cos((y+x*0.33)*0.1));
}
 
// PSandP5draw.pde
// Draws to Processing and Postscript simultaneously
// by replacing calls to fill(), line() etc. by
// custom functions that carry out operations in both.


import SimplePostscript.*;


SimplePostscript ps;
float x,y,px,py;

void setup() {
  size(600,400);
  background(255);
  framerate(5); // Run slow...
  ps=new SimplePostscript(this);
  ps.open("abstract01.ps", 0,0, width,height);
  ps.isOpen=true;
  x=0;
  y=0;
  smooth();
}

void draw() {
  px=x;
  py=y;
  x=random(width);
  y=random(height);
  doStroke(255,0,0);
  doLine(px,py, x,y);

  noStroke();
  doFill(0,200,255);
  doEllipse(px,py, 10,10);
}

void doStroke(float r,float g,float b) {
  stroke(r,g,b);
  if(ps.isOpen) ps.setrgb((int)r,(int)g,(int)b);
}

void doFill(float r,float g,float b) {
  fill(r,g,b);
  if(ps.isOpen) ps.setrgb((int)r,(int)g,(int)b);
}

void doLine(float x1,float y1,float x2,float y2) {
  line(x1,y1,x2,y2);
  if(ps.isOpen) {
    ps.moveto(x1,height-y1);
    ps.lineto(x2,height-y2);
    ps.stroke();
  }
}

void doEllipse(float x,float y,float xrad,float yrad) {
  ellipse(x,y, xrad,yrad);
  if(ps.isOpen) {
    ps.circle(x,height-y,xrad/2);
    ps.fill();
  }
}

void keyPressed() {
  if(!online && key=='s') {
// Print black border around canvas
    ps.setrgb(0,0,0);
    ps.moveto(0,0);
    ps.lineto(width,0);
    ps.lineto(width,height);
    ps.lineto(0,height);
    ps.lineto(0,0);
    ps.strokeclosepath();

// Close file and set ps.isOpen to false
    ps.close();
    ps.isOpen=false;
  }
}
    
 
Copyright 2004, Marius Watz. Built with Processing.