Circle grid - Pixel to mm conversion - Boudaries (help)

hi, I would like to ask two things about this code: Is there in Processing a function that converts pixels to millimeter ? I would like to decide the dimension of the output file (PDF) in mm (A4, 210x297 mm) (now is 847x1.237) and the precise diameter dimension (5mm) of the circles in the drawing.

I do not understand which is the (math) operation to convert pixel to mm related by a resolution (e.g. 300 dpi).

I can control the start position of the circles at the beginning on the left for the x and on the top for y but I am not able to decide the precise end at the boundaries on the right and on the bottom of the page.

Any suggestions, please? Thank you

import processing.pdf.*;

//float diam = 30.24;
float diam = 90.791;

void setup(){
  //fullScreen();
  size(2480, 3508, PDF, "cirleGrid5.pdf");
  //size(4960, 7016, PDF, "cirleGrid3.pdf");

  background(255);
}  

void draw(){ 
  for(float x = 0; x <= width ; x += diam ){
    for(float y= 0; y <= height ; y += diam ){
      //noStroke();
      stroke(150);
      ellipseMode(CORNER);
      ellipse(x, y, diam,diam);
    } 
  }
  println("finish");
  exit();
}
Tagged:

Answers

  • edited December 2015 Answer ✓

    Is there in Processing a function that converts pixels to millimetre?

    Doubtful since millimetre dimensions are determined by output resolution; which is dependent on output format: e.g. screen dpi varies widely...

    I do not understand which is the (math) operation to convert pixel to mm related by a resolution (e.g. 300 dpi).

    dpi = dots per inch: an arcane measurement unit still used in some backwards parts of the world >:)

    1inch = 25.4mm

    300dpi / 25.4 = ~11.81 dots per millimeter

    5mm = 11.81 * 5 = 59 'dots'

    I think that should work; but I doubt it will be 100% accurate and you might have to take into account where strokes are drawn - e.g. if on the outside of the shape that will increase its actual size...

  • edited December 2015

    thank you blindfish,

    this is the code in readable form. if dpi is similar to ppi (?), if I wanted to print the circle at 5mm at 300 dpi I could specify the diameter: 59 'dots' (pixel in the code).

    If you try the code, it produces a pdf in its sketch folder, in the for loop every cicle it draws a circle adding the diameter (50px) but the last circle on the left and on bottom exceeds the edges (width and height). How can I constrain the loop within the page boundaries ??

    thank you

    import processing.pdf.*;
    
    float diam = 50;
    
    void setup(){
      size(2480, 3508, PDF, "cirleGrid5.pdf");
      //size(4960, 7016, PDF, "cirleGrid3.pdf");
      background(255);
    }  
    
    void draw(){ 
      for(float x = 0; x <= width ; x += diam ){
        for(float y= 0; y <= height ; y += diam ){
          //noStroke();
          stroke(150);
          ellipseMode(CORNER);
          ellipse(x, y, diam,diam);
        } 
      }
      println("finito");
      exit();
    }
    
  • size(595, 842); //produces an img 210 x 297mm

Sign In or Register to comment.