| Refresh | Home EGTry.com

create a grid postscript with a perl script


the grid and numbers rendered by postscript

c:/capture/number grid

perl script that produce postscript file

use strict;

my $fontsize="30";
my $inch=72;
my $LeftMargin=$inch;
my $RightMargin=$inch-36;
my $TopMargin=$inch;
my $BottomMargin=$inch;


my $PaperWidth=8.5*$inch;
my $PaperHeight=11*$inch;

my $width=($PaperWidth-$LeftMargin-$RightMargin)/10;
my $height=($PaperHeight-$TopMargin-$BottomMargin)/10;

#header
print "%!PS\n";
print "/Courier findfont \n";
print "$fontsize scalefont \n";
print "setfont \n\n";
print "newpath \n";
# grid

foreach my $row ( 0 .. 9) {
	my $y1=$BottomMargin+$row*$height;
	foreach my $col ( 0 .. 9) {
	my $x1=$LeftMargin+$col*$width;
	my $number=$col+(9-$row)*10;
	my $tx=$x1+5;
	my $ty=$y1+$height-$fontsize-2;

	print <<_box;
	newpath
	$x1 $y1 moveto
	$width 0 rlineto
	0 $height rlineto
	-$width 0 rlineto
	closepath
	stroke
	newpath
	$tx $ty moveto
	($number) show
	
_box
	}
}

#end
print "showpage \n";