#!/usr/bin/perl # Make some line grids... # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.html # Created: 2024-05-26T00:05:40+0000 # Last-Updated: 2024-05-29T00:05:40+0000 # Update #: 78 # use strict; use warnings q!all!; use Getopt::Long; my $mode; #which axis, 0 is E/W axis, 1 is N/S my $numbers_per_grid; my $offset; # to avoid putting points on top of road intersections, ## and thus avoid confusion about which road our numbers are referring to. my $rows ; ## How many rows of labels do we want? E.g., 6 gives 6 vertical and 6 horizontal. my @range; ##--range -1200 200 means 1200 S or W to 200 N or E GetOptions( "mode=i" => \$mode, "numbers_per_grid=i" => \$numbers_per_grid, "offset=i" => \$offset, "rows=i" => \$rows, "range=i{2}" => \@range, ) or die("Error in command line arguments\n"); die "No mode (0 or 1) given." unless defined $mode; die "We weren't told how many --rows" unless $rows; die "We don't know the --range start and end" unless @range == 2; unless ( defined $offset ) { $offset = $numbers_per_grid / 2; } { my @tmp = @range; undef @range; for ( my $v = $tmp[0] ; $v <= $tmp[1] ; $v += $numbers_per_grid ) { push @range, $v; } } $rows--; my @row_pointer; for ( 0 .. $rows ) { push @row_pointer, $range[ $#range / $rows * $_ ]; } for my $a (@row_pointer) { for my $b (@range) { my @to_print; push @to_print, ( $mode ? $a : $b ) + $offset * $mode, ( !$mode ? $a : $b ) + $offset * !$mode; push @to_print, $to_print[$mode], abs( $to_print[$mode] ) . ( $mode ? ( $to_print[$mode] >= 0 ? "N" : "S" ) : ( $to_print[$mode] >= 0 ? "E" : "W" ) ); print "@to_print$/"; } }