#!/afs/athena/contrib/perl/perl

srand;
$SIG{'INT'} = 'sighandler';
$SIG{'HUP'} = 'sighandler';
$SIG{'QUIT'} = 'sighandler';
$|=1;
do "./xbase.perl";
print("Beginning\n");
print &xlib'x_open_display($ENV{'DISPLAY'});
foreach $col (0..20){
$mygc[$col] = &xlib'x_create_gc($xlib'root_window,$xlib'defines{'GCForeground'}
| $xlib'defines{'GCBackground'}, $col, $xlib'root_white);
}
&xlib'x_clear_area($xlib'root_window, 0, 0, 0, $xlib'rootw, $xlib'rooth);


$x1 = rand($xlib'rootw);
$y1 = rand($xlib'rooth);
$vx1 = rand(5);
$vy1 = rand(5);

$x2 = rand($xlib'rootw);
$y2 = rand($xlib'rooth);
$vx2 = rand(5);
$vy2 = rand(5);
while(1){
&xlib'x_clear_area($xlib'root_window, 0, 0, 0, $xlib'rootw, $xlib'rooth);
$vx1 = rand(8);
$vy1 = rand(8);
$vx2 = rand(8);
$vy2 = rand(8);

for (1..1000){
    $ax1 = -(($x1-$x2)/$xlib'rootw);
    $ay1 = -(($y1-$y2)/$xlib'rooth);

    $ax2 = (($x1-$x2)/$xlib'rootw);
    $ay2 = (($y1-$y2)/$xlib'rooth);

    $vx1 += $ax1;
    $vx2 += $ax2;
    $vy1 += $ay1;
    $vy2 += $ay2;

    $x1 += $vx1;
    $y1 += $vy1;

    $x2 += $vx2;
    $y2 += $vy2;

    if($x1 > $xlib'rootw){$vx1 = -$vx1;$x1 = $xlib'rootw;}
    if($x1 < 0) { $vx1 = -$vx1;$x1 = 0;}
 
    if($y1 > $xlib'rooth){$vy1 = -$vy1;$y1 = $xlib'rooth;}
    if($y1 < 0) { $vy1 = -$vy;$y1 = 0;}

    if($x2 > $xlib'rootw){$vx2 = -$vx2;$x2 = $xlib'rootw;}
    if($x2 < 0) { $vx2 = -$vx2;$x2 = 0;}
 
    if($y2 > $xlib'rooth){$vy2= -$vy2;$y2 = $xlib'rooth;}
    if($y2 < 0) { $vy2 = -$vy2;$y2 = 0;}

    &drawline(3, $x1, $y1, $x1-$vx1, $y1-$vy1);
    &drawline(2, $x2, $y2, $x2-$vx2, $y2-$vy2);
}

}

sub drawline {
    local($color, $x, $y, $nx, $ny) = @_;
&xlib'x_line($xlib'root_window, $mygc[$color], 0, $x, $y, $nx, $ny);
#foreach $glkasj (1.100){}
}

sub sighandler {
    exit(0);
}
