#!/usr/bin/perl -w use CGI; my $q = new CGI; print $q->header; if(!$q->param()) { &print_empty_form; } else { &create_grid; } sub create_grid { # Make sure these variables contain valid values or a default value for a nice grid. $width = ($q->param('width') =~ /(\d{1,2})/)[0] || 30; my $height = ($q->param('height') =~ /(\d{1,2})/)[0] || 30; $ulx = ($q->param('ULX') =~ /(-?\d{1,3})/)[0] || 1; my $uly = ($q->param('ULY') =~ /(-?\d{1,3})/)[0] || 1; my $xaxis = ($q->param('XAxis') =~ /(\d{1,2})/)[0] || 0; my $yaxis = ($q->param('YAxis') =~ /(\d{1,2})/)[0] || 0; my $xoption = $q->param('XOption'); my $yoption = $q->param('YOption'); my $xtop = $q->param('XTop'); my $xbottom = $q->param('XBottom'); $yleft = $q->param('YLeft'); $yright = $q->param('YRight'); my $border = ($q->param('border') =~ /(\d{1,2})/)[0] || 0; my $cellspacing = ($q->param('cellspacing') =~ /(\d{1,2})/)[0] || 0; my $cellpadding = ($q->param('cellpadding') =~ /(\d{1,2})/)[0] || 0; $fill = ($q->param('fill') =~ /(.{1,3})/)[0] || " + "; $fill =~ s/ / /g; if($ulx < -99) { $ulx /= 10; $ulx = int $ulx; } # I don't know whether it's necessary if($uly < -99) { $uly /= 10; $uly = int $uly; } # to int them, but it might be safer. $perx = 0; $pery = 0; if($xaxis > 0) { if($xoption eq "XTimes") { $pery = $ width / ($xaxis+1); } else { $pery = $xaxis; } } if($yaxis > 0) { if($yoption eq "YTimes") { $perx = $height / ($yaxis+1); } else { $perx = $yaxis; } } print "($width x $height) Grid starting at ($ulx,$uly)"; print ""; # I don't want to force people to print a stupid banner! They'll prefer to click away the stupid popup instead! print "\n"; print "\n"; &print_x_axis if $xtop eq "yes"; my $iy = 1; for ($uly .. $uly + $height - 1) { &print_row($_); if($pery > 0 && $iy - $pery > 0 && $_ < $uly + $height - 1) { $iy -= $pery; &print_x_axis; } $iy++; } &print_x_axis if $xbottom eq "yes"; print "
\n"; } sub print_x_axis { my $ix = 1; print ""; print " " if $yleft eq "yes"; for ($ulx .. $ulx + $width - 1) { if(length == 1) { print " ${_} "; } elsif(length == 2) { print " $_"; } else { print "$_"; } if($perx > 0 && $ix - $perx > 0 && $_ < $ulx + $width - 1) { $ix -= $perx; print ""; } $ix++; } print " " if $yright eq "yes"; print "\n"; } sub print_row { my $ix = 1; print ""; print "$_[0]" if $yleft eq "yes"; for ($ulx .. $ulx + $width - 1) { print "$fill"; if($perx > 0 && $ix - $perx > 0 && $_ < $ulx + $width - 1) { $ix -= $perx; print "$_[0]"; } $ix++; } print "$_[0]" if $yright eq "yes"; print "\n"; } sub print_empty_form { print <Grid Generator

Grid Generator

Size options
Grid size: ( , )
Offset options
Upper-left corner co-ordinates are: ( , )
Axis options
Display X axis at top, bottom
Display Y axis at left, right side
Additional axes within the grid
Display an additional X axis within the grid
Display an additional Y axis within the grid
Additional options
Fill grid with Table border
Table cellspacing Table cellpadding
HERE }