mmcirvin: (Default)
[personal profile] mmcirvin
[livejournal.com profile] iayork's adventures in iTunes scripting inspired me to get around to doing something [livejournal.com profile] samantha2074 had suggested. She'd seen some cheeseball commercial program that printed out customizable graph paper, and she asked me, "You can do that, right?" Apparently this is sought after by knitters; it's rather expensive graph paper, but they like to be able to make it in any pitch, especially if they can specify, say, the number of boxes (representing stitches) per 4-inch or 10-centimeter interval.

I balked at the idea of actually learning to write a Windows application, or any kind of usable PC application for that matter (I have about one day's experience with Cocoa on the Mac), but then realized that I didn't have to do that. I could just write a very simple PostScript program with easy-to-customize parameters, which for reasons of my former employment I am actually able to do, and Sam was more than capable of editing it and running Ghostscript to print it out. This evening I spent a few minutes banging it out.


%!PS
%
% graph.ps, Matt McIrvin, July 2004
%
% A customizable sheet of graph paper for Sam's knitting.

/unit /in def		% possible values: in or cm

/length 4 def		% the length over which the number of stitches is defined

/stitchesX 25 def	% stitches in the horizontal direction

/stitchesY 25 def	% stitches in the vertical direction

0 setgray			% lightness of the lines; 0 means black
				% Replace this line with <r> <g> <b> setrgbcolor,
				% <c> <m> <y> <k> setcmykcolor for other options;
				% 1 0 0 0 setcmykcolor is light blue-green (cyan)

0 setlinewidth	% line width in points (1/72 inch)
				% zero here means a single-pixel hairline

/lengthPts
unit /in eq
{
	length 72 mul
}
{
	length 2.54 div 72 mul
}
ifelse
def

/pageWidth 8.5 72 mul def
/pageHeight 11 72 mul def

% draw the vertical lines

0
lengthPts stitchesX div
pageWidth
{
	dup 0 moveto pageHeight lineto stroke
}
for

% draw the horizontal lines

0
lengthPts stitchesY div
pageHeight
{
	dup 0 exch moveto pageWidth exch lineto stroke
}
for

showpage


February 2026

S M T W T F S
1234567
8910 11121314
15 161718192021
22232425262728

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 17th, 2026 08:31 am
Powered by Dreamwidth Studios