FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Integration
(Moderators: fry, REAS)
   print to EPS
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: print to EPS  (Read 1098 times)
Aaron Wilson
Guest
Email
print to EPS
« on: Mar 9th, 2004, 10:47pm »

Hello All,
 
I have been generating a number of still images using Processing, and I am curious if anyone knows a way to print to an EPS file that could be imported into Illustrator for large-scale high-res prints.
 
I have done this in Flash using an EPS printer driver, but that required the right-click print menu that is built into the Flash player.
 
Any thoughts?
 
Thaks a bunch,
 
Aaron
 
REAS


WWW
Re: print to EPS
« Reply #1 on: Mar 9th, 2004, 11:16pm »

Marius Watz has written code for writing PostScript files. These can be read into programs such as Illustrator. Check the link called "Simple Postscript Output" on the TechNotes page:
http://processing.org/reference/technotes/index.html
 
In the future we hope to include a complete vector export library with Processing.
 
-- edit
 
From the technotes page, also follow the link called "Processing to Paper"
« Last Edit: Mar 9th, 2004, 11:23pm by REAS »  
amoeba

WWW
Re: print to EPS
« Reply #2 on: Mar 10th, 2004, 11:41am »

Hi Aaron,
 
As Casey mentioned you can use my SimplePostscript library to do that, although you have to provide the translation from Processing to PostScript graphics yourself.  
 
The simplest way to draw both to Processing and Postscript at the same time is to replace (or overload) calls to line(), fill() etc. so that they carry out these actions both on the screen and in a file. I did this recently, and it worked out fine as long as I used only lines, ellipses and rectangles. See sample code below.
 
Alpha is obviously not supported, so your graphics have to be PostScript-friendly to begin with. Note that the Y-axis is reversed in Postscript (positive Y being up), use "height-y" to reverse it back. To do 3D you could potentially use screenX(), screenY() to do the conversions, but I'm not sure whether they would work with complex transformations etc. Hmm, should try it to see.
 
Good luck!
 
Code:
boolean fileOpen=false;
SimplePostscript ps;
float x,y,px,py;
 
void setup() {
  size(600,400);
  background(255);
  ellipseMode(CENTER_DIAMETER);
  framerate(5); // Run slow...
  ps=SimplePostscript.open("abstract01.ps", 0,0, width,height);
  fileOpen=true;
  x=0;
  y=0;
  smooth();
}
 
void loop() {
  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(fileOpen) ps.setrgb((int)r,(int)g,(int)b);
}
 
void doFill(float r,float g,float b) {
  fill(r,g,b);
  if(fileOpen) ps.setrgb((int)r,(int)g,(int)b);
}
 
void doLine(float x1,float y1,float x2,float y2) {
  line(x1,y1,x2,y2);
  if(fileOpen) {
    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(fileOpen) {
    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 fileOpen to false
    ps.close();
    fileOpen=false;
  }
}

 
Obviously, the above requires SimplePostscript.class to be in the "code" folder of your sketch. Download from SimplePostscript.
« Last Edit: Mar 10th, 2004, 11:58am by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
TomC

WWW
Re: print to EPS
« Reply #3 on: Mar 10th, 2004, 12:48pm »

Nice.  Is there a reason (fry? REAS?) that BApplet methods are final?  If they weren't, couldn't we use identical code instead of the 'do' version above, and then write methods like:
 
Code:

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

 
fry


WWW
Re: print to EPS
« Reply #4 on: Mar 10th, 2004, 2:20pm »

on Mar 10th, 2004, 12:48pm, TomC wrote:
Nice.  Is there a reason (fry REAS) that BApplet methods are final  If they weren't, couldn't we use identical code instead of the 'do' version above, and then write methods like:

the math (abs, min, max) and color math (hue, saturation, etc) functions are set final since that's a hint to the java vm that they can be inlined/compiled and sped up. the rest are not (should not) be final unless they're for internal use, were you running into trouble with one
 
but yes, you're idea for drawing to both should work. one of the major holdups to getting postscript (and opengl) support into p5 is deciding how to handle drawing to screen or file or opengl or some combination thereof (without needlessly slowing down apps that only need one). most of the solutions are too general (and therefore slow) or too specific (preventing others from writing their own).
« Last Edit: Mar 10th, 2004, 2:22pm by fry »  
TomC

WWW
Re: print to EPS
« Reply #5 on: Mar 10th, 2004, 4:02pm »

on Mar 10th, 2004, 2:20pm, fry wrote:

were you running into trouble with one

 
Yes, but it was my fault.  Not that they're final, but they are public.  Fixed now.
 
This works as above, but the loop() is normal Processing (oh and save checks if the file is open ).
 
Code:

 
boolean fileOpen=false;  
SimplePostscript ps;  
float x,y,px,py;  
 
void setup() {  
  size(600,400);  
  background(255);  
  ellipseMode(CENTER_DIAMETER);  
  framerate(5); // Run slow...  
  ps=SimplePostscript.open("abstract01.ps", 0,0, width,height);  
  fileOpen=true;  
  x=0;  
  y=0;  
  smooth();  
}  
 
void loop() {  
  px=x;  
  py=y;  
  x=random(width);  
  y=random(height);  
  stroke(255,0,0);  
  line(px,py, x,y);  
   
  noStroke();  
  fill(0,200,255);  
  ellipse(px,py, 10,10);  
}  
 
public void stroke(float r,float g,float b) {  
  super.stroke(r,g,b);  
  if(fileOpen) ps.setrgb((int)r,(int)g,(int)b);  
}  
 
public void fill(float r,float g,float b) {  
  super.fill(r,g,b);  
  if(fileOpen) ps.setrgb((int)r,(int)g,(int)b);  
}  
 
public void line(float x1,float y1,float x2,float y2) {  
  super.line(x1,y1,x2,y2);  
  if(fileOpen) {  
    ps.moveto(x1,height-y1);  
    ps.lineto(x2,height-y2);  
    ps.stroke();  
  }    
}  
 
public void ellipse(float x,float y,float xrad,float yrad) {  
  super.ellipse(x,y, xrad,yrad);  
  if(fileOpen) {  
    ps.circle(x,height-y,xrad/2);  
    ps.fill();  
  }  
}  
 
void keyPressed() {  
  if(!online() && key=='s') {  
    if (fileOpen) {
 // 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 fileOpen to false  
 ps.close();  
 fileOpen=false;  
    }
  }  
}  
 
 
amoeba

WWW
Re: print to EPS
« Reply #6 on: Mar 10th, 2004, 6:29pm »

That's great, Tom. I agree, overloading is nicer, I just thought I would leave it out not to confuse non-OOP'ers....
 
On another note, for things like this it would be great if the state of the internal graphics engine would be accessible. I'm planning to write a similar library to output 3D object files for the freeware POV-Ray raytracer. I've been using it for years, and it's great for generative work since the file format is very simple and the rendering results are great. No GUI, but hey, it's free...
« Last Edit: Mar 10th, 2004, 6:34pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
amoeba

WWW
Re: print to EPS
« Reply #7 on: Mar 10th, 2004, 8:23pm »

OK, just a testimonial to the power of PostScript and vector graphics:
 
Images for an article about Processing.  
 
See the details page to see how nice it looks up close. These were created by modified versions of already published Processing pieces, changed to output to PostScript using SimplePostscript as described previously in this thread.
 
The article will be published in next issue of XFUNS magazine, which I think will feature an interview with Casey.
« Last Edit: Mar 11th, 2004, 12:16am by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
Pages: 1 

« Previous topic | Next topic »