#!/usr/local/bin/perl
#Changes background color and text every second
#file: nph-test.pl

require '/home/bear-008/users/downeyt/scripts/parse-lib.pl';

$|=1;
$BOUNDARY = "----------here-it-comes!";

print <<HEADER;
Status: 200 OK
Server: $ENV{SERVER_SOFTWARE} / Tim's script
Content-type: multipart/x-mixed-replace; boundary=$BOUNDARY

HEADER
    ;
$inc=1000;
$count=0;
$max = hex "FFFFFF";
print $max;
while (1)
{
    $back = &encode_hex($count);
    $text = &encode_hex ($max - $count);
    &print_page($back,$text);
    sleep(1);
    $count+=$inc;
    $count = $count % $max;
}
    
sub print_page {
    local($back,$text)=@_;

print <<PAGE;
$BOUNDARY
Content-type: text/html

<html>
<head>
<title>$back</title>
</head>
<body bgcolor=#$back text=#$text>
<h1 align=center>bgcolor=#$back, text=#$text</h1>
</body>
</html>
PAGE
    ;
}    

sub encode_hex {
    my($num)=@_;
    my($str,$i,$digs);

    while ($num > 0)
    {
	$rem = $num % 16;
	$num = int ($num / 16);
	$rem = &hex_digit ($rem) if ($rem > 9);
	$str = $rem . $str;
	$digs++;
    }

    for ($i = 0; $i < 6 - $digs; $i++)
    {
	$str = "0" . $str;
    }

    return $str;
}

sub hex_digit {
    my($rem) = @_;
    
    if ($rem == 10) {return "A"}
    elsif ($rem == 11) {return "B"}
    elsif ($rem == 12) {return "C"}
    elsif ($rem == 13) {return "D"}
    elsif ($rem == 14) {return "E"}
    elsif ($rem == 15) {return "F"}
    else  {return "Error in hex digit"}
}








