Calculate PDF/Window size in Processing
Some easy math to calculate the size of your Processing window so you don't need to resize your work before you send it to the lasercutter.
Let's say you want to create a work of 20 x 30 centimer. Processing displays everything on screen wiht a resolution of 72 dpi.
- 20 cm = 200 mm.
- 1 inch = 25.4mm
- 200mm / 25.4mm = 7.87401... inch
- 7.87401... * 72dpi = 566.9 = 567 pixels
Converting 30 cm to pixels would look like this:
300mm = 11.811 inch = 850.393 = 850 pixels
In the setup method of your Processing sketch, you can use size( 567, 850 ). If you save a PDF, the output will be the right size for lasercutting.
Alternate method
An alternative method could be to use the presets build in the PDF library used by Processing.
The code has been taken from Toxi's example and updated to run in Processing 1.5*
/** * Convenience method to be used instead of the normal size() command. * Creates a window matched to a given paper size * * @credit Toxi http://toxi.co.uk/blog/2007/07/specifying-pdf-page-size-in-processing.htm * * @param r a predefined constant of the iText PageSize class * @param isLandscape true, if you want landscape orientation * @param renderer class name of the Processing renderer to use */ void pageSize(com.lowagie.text.Rectangle r, boolean isLandscape, String renderer) { if (isLandscape) { size((int)r.getTop(),(int)r.getRight(),renderer); } else { size((int)r.getRight(),(int)r.getTop(),renderer); } }
And use it like that in your setup() function
// You need to import the PDF library to get access to the PageTize persets import processing.pdf.*; void setup() { // create window @ A4 portrait pageSize(com.lowagie.text.PageSize.A4, false, P2D); }
Check this list for the available standard paper sizes. If yours is not present... fall back to the previous calculating method ;)
Info
Difficulty: ●○○○○
Last updated: February 2012