mm-grid in PostScript

Posted on

Suddenly started to feel like i must make a mm-grid sheet urgently. Decided to read about PostScript finally.

Here is a resulted pdf (ps2pdf mm-grid.ps) — pdf, 54K.

Definitely, it’s not the best algorithm :O)

I will improve .)

Update: here is a better one.

%!PS-Adobe-2.0
%%DocumentPaperSizes: a4
%%EndComments
 
/mm { 2.8346457 mul } def
 
/mmthickness     0.2 def
/cmthickness     1.0 def
/fivemmthickness 0.6 def
 
/horgrid {
        % two thick horizontal lines:
        0 0 moveto
        10 mm 0 rlineto
        -10 mm 10 mm rmoveto
        10 mm 0 rlineto
        cmthickness setlinewidth
        stroke
        % one semi-thick (5mm) horizontal line:
        0 5 mm moveto
        10 mm 0 rlineto
        fivemmthickness setlinewidth
        stroke
        % nine thin horizontal lines:
        0 1 mm moveto
        9 {
                10 mm 0 rlineto
                -10 mm 1 mm rmoveto
        } repeat
        mmthickness setlinewidth
        stroke
} def
 
% 1x1 cm grid:
/cube {
        horgrid
        10 mm 0 translate
        90 rotate
        horgrid
        -90 rotate
} def
 
% go to initial position:
25 mm 25 mm translate
 
% 16x25 cm grid:
25 {
        16 {
                0 0 translate
                cube
        } repeat
        -160 mm 10 mm translate
} repeat
 
showpage
 
% i liked that!

Leave a Reply

Your email address will not be published. Required fields are marked *

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