smooth images with the pdf-renderer

The images of the tilings look good on the computer screen but not so if printed out. We do not want to see pixels on paper. We could remedy this using roughly 16 times as much pixels, because the computer shows 72 pixels per inch and a printer has typically 300 dots per inch. But this makes large image file sizes and if we want an enlarged image we would again see pixels.

We get smooth images at every scale if we create it in a pdf-file. Fortunately, processing has a library to do this, see It has to be loaded using

import processing.pdf.*;

in the beginning of the code. Then, before drawing the image, a pdf-file is initialized with

 beginRecord(PDF, "filename.pdf");

Afterwards, every object we draw is recorded in this file. To finish the file we have to use


and we can open the file in a pdf-viewer to see it at any magnification, to print it and to copy it.

But it is inconvenient that the file is put into the folder of the processing sketch. I want to be able to choose its name and its folder. unfortunately, a pdf-file has not an image icon and its name often does not tell much. Thus I want to have a *.png file with an image icon along with the *.pdf-file of the same name. To do this I created new code that replaces the earlier code of saveImage, see “saving images” and following posts. This is it:

// replaces the earlier code of saveImage
// to get better images use
// strokeJoin(ROUND); 

void whereToSave(){
 selectOutput(" where do you want to save the image ?","saveImageCallback"); 

void saveImageCallback(File selection) {
 if (selection!=null) {filePath=selection.getAbsolutePath();
 String[] filePathPieces=split(filePath,"."); 
 if(filePathPieces.length==1) filePath=filePathPieces[0]+".png";
 println("Picture output filepath is: "+filePath);
 println("PDF output filepath is: "+pdfPath);


void startImage(){
 if(pdfPath!=null) beginRecord(PDF,pdfPath);

void saveImage(){
 if(filePath!=null) save(filePath);
 if(pdfPath!=null) endRecord();

Because “beginRecord” needs already the file name before drawing can begin everything becomes a bit more complicated. The file chooser “selectOutput” is now called in “setup()”. While the file chooser is open and we are thinking of a fancy name, the program is still running. It can set up the grids and dualize the tiling. But in “draw()” the program has first to wait until the file chooser has finished. For this reason, the callback function “saveImageCallback(…)” sets the boolean whereToSaveDone=true. Then we can begin drawing. A typical main tab looks like that

import processing.pdf.*;
String filePath, pdfPath;
boolean whereToSaveDone=false;

void setup(){


 // continue to prepare image, without drawing
 // ??????????????????????????????

void draw(){


 // now draw the image



Note that we are not obliged to give a file name. If we choose “cancel” in the file chooser, the program still generates the image but stores nothing. We might even replace “whereToSave();” by “whereToSaveDone=true;” and thus eliminate the dialogue entirely to speed up our work until we have found the final image.

To get good corners of polygons I recommend to use “strokeJoin(ROUND);” in “setup()”. This is especially important for acute angles.

This entry was posted in Extra, programming, Quasiperiodic design, Tilings and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.