commit a5bf76555b24f319675d49cbcc45d3a622174d8d
parent 19404e1be43a5d0fcbdcf193c83602142c0bb54f
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Mon, 30 Oct 2023 21:39:34 -0700
More graph paper types
I was having fun with PostScript programming so I made other kinds of graph
paper: 1 inch hex grids (if you know you know) and a 5 mm dot grid (which is
great for turning scrap paper into note paper). I still need to update the
post but I thought I'd tuck these here for now anyway.
Diffstat:
6 files changed, 126 insertions(+), 0 deletions(-)
diff --git a/content/posts/postscript-graph-paper/dotgrid.pdf b/content/posts/postscript-graph-paper/dotgrid.pdf
Binary files differ.
diff --git a/content/posts/postscript-graph-paper/dotgrid.ps b/content/posts/postscript-graph-paper/dotgrid.ps
@@ -0,0 +1,28 @@
+%!PS
+% Adjust these to suit your needs, units specified in "points" (1/72 inch)
+/w 612 def /h 792 def % US Letter paper
+/sp 5 72 mul 25.4 div def % Grid spacing (5 mm here)
+/st 1 72 mul 300 div def % Dot radius (1 'dots' in a 300 dpi resolution)
+/co 0.0 def % Gray-level of the line (0 = black, 1 = white)
+
+% Remainder function (`mod` doesn't take floating point values)
+/r {dup 3 1 roll div dup floor sub mul} def
+% Return the starting offset that centers the grid
+/o {r 2 div} def
+% Draw a dot (x y -- )
+/dot {st 0 360 arc closepath fill} def
+
+% Page and line setup
+<< /PageSize [w h] >> setpagedevice
+co setgray
+h sp o
+sp h
+{
+ w sp o
+ sp w
+ {
+ 1 index % (y x -- y x y)
+ dot % (y x y -- y)
+ } for
+ pop
+} for
diff --git a/content/posts/postscript-graph-paper/grid.pdf b/content/posts/postscript-graph-paper/grid.pdf
Binary files differ.
diff --git a/content/posts/postscript-graph-paper/grid.ps b/content/posts/postscript-graph-paper/grid.ps
@@ -0,0 +1,37 @@
+%!PS
+% Adjust these to suit your needs, units specified in "points" (1/72 inch)
+/w 612 def /h 792 def % US Letter paper
+/sp 5 72 mul 25.4 div def % Grid spacing (5 mm here)
+/st 1 72 mul 300 div def % Stroke width (1 'dots' in a 300 dpi resolution)
+/co 0.6 def % Gray-level of the line (0 = black, 1 = white)
+
+% Remainder function (`mod` doesn't take floating point values)
+/r {dup 3 1 roll div dup floor sub mul} def
+% Return the starting offset that centers the grid
+/o {r 2 div} def
+
+% Page and line setup
+<< /PageSize [w h] >> setpagedevice
+co setgray
+st setlinewidth
+
+% Create vertical lines
+w sp o
+sp w
+{
+ dup
+ 0 moveto
+ h lineto
+} for
+
+% Create horizontal lines
+h sp o
+sp h
+{
+ dup
+ 0 exch moveto
+ w exch lineto
+} for
+
+% Draw
+stroke
diff --git a/content/posts/postscript-graph-paper/hexgrid.pdf b/content/posts/postscript-graph-paper/hexgrid.pdf
Binary files differ.
diff --git a/content/posts/postscript-graph-paper/hexgrid.ps b/content/posts/postscript-graph-paper/hexgrid.ps
@@ -0,0 +1,61 @@
+%!PS
+% Adjust these to suit your needs, units specified in "points" (1/72 inch)
+/w 612 def /h 792 def % US Letter paper
+/st 1 72 mul 300 div def % Stroke width (1 'dots' in a 300 dpi resolution)
+/co 0.6 def % Gray-level of the line (0 = black, 1 = white)
+/hw 1 72 mul def % Width of a hex (1 inch)
+
+% Derived variables
+/hh hw 2 mul 3 sqrt div def % Hex height
+/hhw hw 2 div def % Half hex width
+/qhh hh 4 div def % Quarter hex height
+/th hh 1.5 mul def % Tile height
+/tw hw def % Tile width
+/hcx hhw def % Center of a hex within the tile (x)
+/hcy hh 1.25 mul def % Center of a hex within the tile (y)
+
+% Draw one tile of a repeating hex pattern. This coves one hex width and 1.5
+% hex heights
+% (x y -- )
+/drawtile {
+ moveto
+ hhw qhh rlineto
+ 0 qhh 2 mul rlineto
+ hhw -1 mul qhh rlineto
+ 0 qhh 2 mul rlineto
+ hhw qhh -5 mul rmoveto
+ hhw qhh -1 mul rlineto
+ hhw -1 mul qhh 3 mul rmoveto
+ hhw qhh rlineto
+ stroke
+} def
+
+% Find the starting point of the first tile along the given coordinate
+% (page-size tile-size hex-center -- tile-start)
+/start-tiles {
+ /hex-center exch def
+ /tile-size exch def
+ /page-size exch def
+ page-size 2 div hex-center sub
+ page-size tile-size div 2 div floor
+ tile-size mul
+ sub
+} def
+
+% Page and line setup
+<< /PageSize [w h] >> setpagedevice
+co setgray
+st setlinewidth
+
+% Draw the grid so that one hex is centered in the page center
+h th hcy start-tiles
+th h
+{
+ w tw hcx start-tiles
+ tw w
+ {
+ 1 index % (y x -- y x y)
+ drawtile % (y x y -- y)
+ } for
+ pop
+} for