grid.ps (767B)
1 %!PS 2 % Adjust these to suit your needs, units specified in "points" (1/72 inch) 3 /w 612 def /h 792 def % US Letter paper 4 /sp 5 72 mul 25.4 div def % Grid spacing (5 mm here) 5 /st 1 72 mul 300 div def % Stroke width (1 'dots' in a 300 dpi resolution) 6 /co 0.6 def % Gray-level of the line (0 = black, 1 = white) 7 8 % Remainder function (`mod` doesn't take floating point values) 9 /r {dup 3 1 roll div dup floor sub mul} def 10 % Return the starting offset that centers the grid 11 /o {r 2 div} def 12 13 % Page and line setup 14 << /PageSize [w h] >> setpagedevice 15 co setgray 16 st setlinewidth 17 18 % Create vertical lines 19 w sp o 20 sp w 21 { 22 dup 23 0 moveto 24 h lineto 25 } for 26 27 % Create horizontal lines 28 h sp o 29 sp h 30 { 31 dup 32 0 exch moveto 33 w exch lineto 34 } for 35 36 % Draw 37 stroke