06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

402 <strong>Learning</strong> <strong>Processing</strong><br />

void draw() {<br />

// Begin making the PDF<br />

if (recordPDF) {<br />

beginRaw(PDF, " 3D.pdf " );<br />

}<br />

background(255);<br />

stroke(0);<br />

noFill();<br />

translate(width/2,height/2);<br />

rotateX(xTheta);<br />

rotateY(yTheta);<br />

box(100);<br />

xTheta + = 0.02;<br />

yTheta + = 0.03;<br />

// End making the PDF<br />

if (recordPDF) {<br />

endRaw();<br />

recordPDF = false;<br />

}<br />

}<br />

// Make the PDF when the mouse is pressed<br />

void mousePressed() {<br />

recordPDF = true;<br />

}<br />

Two important notes about the PDF library.<br />

• <strong>Images</strong> —If you are displaying images in the PDF, these will not necessarily look good after export.<br />

A 320 � 240 pixel image is still a 320 � 240 pixel image whether rendered in<strong>to</strong> a high-resolution<br />

PDF or not.<br />

• Text —If you are displaying text in the PDF, you will have <strong>to</strong> have the font installed in order <strong>to</strong> view<br />

the PDF properly. One way around this is <strong>to</strong> include “ textMode(SHAPE); ” after size( ) . This will<br />

render the text as a shape <strong>to</strong> the PDF and not require the font installed.<br />

For full documentation of the PDF library, visit the <strong>Processing</strong> reference page at http://processing.org/<br />

reference/libraries/pdf/index.html . While the PDF library will take care of many of your needs related<br />

<strong>to</strong> high-resolution generation, there are two other contributed libraries that might be of interest. One<br />

is proSVG by Christian Riekoff for exporting fi les in the SVG ( “ Scalable Vec<strong>to</strong>r Graphics ” ) format:<br />

http://www.texone.org/prosvg/ . Another is SimplePostScript by Marius Watz for writing vec<strong>to</strong>r fi les in the<br />

PostScript format: http://processing.unlekker.net/SimplePostscript/ .<br />

21.4<br />

Exercise 21-2: Create a PDF from any <strong>Processing</strong> sketch you have made or any example<br />

in this book.<br />

<strong>Images</strong>/ saveFrame( )<br />

If you include “####”<br />

in the fi lename—<br />

“3D-####.pdf”—separate,<br />

numbered PDFs will be<br />

made for each frame that<br />

is rendered.<br />

fi g. 21.4<br />

High-resolution PDFs are useful for printing; however, you can also save the contents of the <strong>Processing</strong><br />

window as an image fi le (with the same resolution as the pixel size of the window itself ). Th is is<br />

accomplished with save( ) or saveFrame( ) .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!