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

$SIG{'INT'} = 'sighandler';
$SIG{'HUP'} = 'sighandler';
$SIG{'QUIT'} = 'sighandler';


do "./xbase.perl";
print("Beginning\n");
&xlib'x_open_display($ENV{'DISPLAY'});
print("Opened!\n");
foreach $col (0..20){
$mygc[$col] = &xlib'x_create_gc($xlib'root_window,$xlib'defines{'GCForeground'}
| $xlib'defines{'GCBackground'}, $col, $xlib'root_white);
}


while(1){
    print("Begin\n");
&xlib'x_clear_area($xlib'root_window, 0, 0, 0, $xlib'rootw, $xlib'rooth);

$e = .66 + rand(1)/3.0;
srand(time);
$x = 0;
$y = 0;
$vx = (rand(12) +rand(2))/2;
$vy = rand(1);

$c = rand(20);
if($c == 4 || $c == 11){$c++;}
int($c);
$| = 1;
while(($vy > .015 || $vy < -.015) || $y != $xlib'rooth){
    $ox = $x;
    $oy = $y;
    $x = ($x + $vx);
    $y = ($y + $vy);
    
    &drawline($c, $ox, $oy, $x, $y);
    if($x > $xlib'rootw){$vx = -$vx;$x = $xlib'rootw;$vx *= $e;}
    if($x < 0) { $vx = -$vx;$x = 0;$vx *= $e;}

    if($y > $xlib'rooth){$vy = -$vy;$y = $xlib'rooth;$vy *= $e;}
    if($y < 0) { $vy = -$vy;$y = 0;$vy *= $e;}
    $vy += .03;
    if($y > ($xlib'rooth + 50)){exit(1);}
#print("($x, $y), ");
#print("$vy, ");
}


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

sub sighandler {
    print("Quitting cleanly... \n");
    exit(0);
}
