#!/usr/bin/perl -w
###################
# from Steve Lidie, 
# chap 39 in "Web, Graphics, and Perl/Tk"
###################

my $chlorophyll = '#8395ffff0000';       # rye-grass-green, maybe
my $color       = 0xffff;                # initial line color
my $cut         = (38 / 12);             # cut width in feet
my $d2r         = 3.14159265/180.0;      # degrees to radians
my $ppf         = 2;                     # pixels per foot
my $side        = 100;                   # size of square mow area
my $turn        = (27 / 12);             # turn radius in feet

use Tk;
my $mw      = MainWindow->new;
my $canvas  = $mw->Canvas( -width      => $side,
			   -height     => $side,
			   -background => $chlorophyll );
$canvas->grid;
$mw->waitVisibility;

mow( $canvas, 0, 0, $side, $side );

# ---------------------------------------------------------

# Recursively mow until done.
sub mow {
    my ($canvas, $x1, $y1, $x2, $y2) = @_;
    return if $x1 >= $x2 or $y1 >= $y2;
    $canvas->createLine($x1,$y1, $x2,$y1, $x2,$y2, $x1,$y2, $x1,$y1);
    $canvas->idletasks;
    $canvas->after(250);
    mow($canvas, $x1+$cut, $y1+$cut, $x2-$cut, $y2-$cut);
}
