#!/usr/local/bin/perl
# blckcrcl.pl - Generate block pattern to fit circle
#
# Copyright 2015 David Meyer <
[email protected]> +JMJ
# (License and documentation at bottom of file.)
# Modules ###########################################################
#use strict;
use warnings;
use Getopt::Std;
# Configuration #####################################################
# Globals ###########################################################
# Functions #########################################################
# Process arguments #################################################
%options = ();
getopts('', \%options);
# Main driver #######################################################
$diam = shift;
print <<END;
<html>
<head>
<title>blckcrcl.pl output</title>
<body>
<table>
<tr>
END
if ($diam % 2 == 0) { # Even diameter
$r = $diam / 2;
for $z (1 .. $r) {
for $x (1 .. $r) {
$dist = sqrt(($x-0.5)**2 + ($z-0.5)**2);
if ($dist <= $r) {$result = '[]';}
else {$result = ' ';}
print "<td>$result</td>";
}
print "</tr>\n";
}
}
else { # Odd diameter
$r = ($diam - 1) / 2;
for $z (0 .. $r) {
for $x (0 .. $r) {
$dist = sqrt($x**2 + $z**2);
if ($dist < ($r + 0.3)) {
if ($z == 0 && $x == 0) {$result = '00';}
elsif ($z == 0) {$result = '--';}
elsif ($x == 0) {$result = '|';}
else {$result = '[]';}
}
else {
$result = ' ';
}
print "<td>$result</td>";
}
print "</tr>\n";
}
}
print "</table>\n</body>\n</html>\n";
exit 0
__END__
# Documentation #####################################################
=head1 NAME
template.pl - Perl script template (command line)
=head1 SYNOPSIS/USAGE
=head1 DESCRIPTION
Mark up code elements with C<>, file names with F<> (or C<> for
readability), command names with B<>. Also I<> for italics, U<> for
underline. Entities: E<lt> ('<'), E<gt> ('>').
=head1 OPTIONS
=item B<-o> I<value>, B<--option>=I<value>
=head1 RETURN VALUE
=head1 ERRORS
=head1 DIAGNOSTICS
=head1 EXAMPLES
=head1 ENVIRONMENT
=over 6
=item VARIABLE
Description of usage of environment variable C<VARIABLE>.
=back
=head1 FILES
=head1 BUGS, LIMITATIONS, AND CAVEATS
=head1 NOTES
=head1 AUTHOR
David Meyer <
[email protected]>
=head1 HISTORY
=head1 COPYRIGHT AND LICENSE
Copyright 201x David Meyer
=head1 SEE ALSO
# Emacs control #####################################################
#Local variables:
#mode: perl
#End: