#!/usr/bin/perl

use GD;

$| = 1;
print "Content-type: image/jpeg", "\n\n";

#$max_length = 175;
$max_wedth = 350;
$max_hight = 175;
$image = new GD::Image ($max_wedth, $max_hight);

$white = $image->colorAllocate (255, 255, 255);
$red = $image->colorAllocate (255, 0, 0);
$blue = $image->colorAllocate (0, 0, 255);

@origin = (30, 140);

# title
$image->string (gdLargeFont, 12, 15, "The Kendrick Effect", $blue);

# Horzontal axis
$image->line (@origin, 250 + $origin[0], $origin[1], $blue);

# Vertical axis
$image->line (@origin, $origin[0], $origin[1] - 105, $blue);

# tick marks on x axis
for ($y_axis=0; $y_axis <= 100; $y_axis = $y_axis + 10) {
	$image->line (  $origin[0] - 5, 
			$origin[1] - $y_axis,
			$origin[0] + 5,
			$origin[1] - $y_axis,
			$blue  );
}

# tick marks on the Horzontal axis
for ($x_axis=0; $x_axis <= 250; $x_axis = $x_axis + 25) {
	$image->line (	$x_axis + $origin[0],
			$origin[1] - 5,
			$x_axis + $origin[0],
			$origin[1] + 5,
			$blue );
}

$uptime = `/usr/ucb/uptime`;
($load_averages) = ($uptime =~ /average: (.*)$/);
@loads[0..2] = split(/,\s/, $load_averages);
sleep 10;
$uptime = `/usr/ucb/uptime`;
($load_averages) = ($uptime =~ /average: (.*)$/);
@loads[3..5] = split(/,\s/, $load_averages);
sleep 10;
$uptime = `/usr/ucb/uptime`;
($load_averages) = ($uptime =~ /average: (.*)$/);
@loads[6..8] = split(/,\s/, $load_averages);

for ($loop=0; $loop < 8; $loop++) {
#    print "loop = $loop load_averages = $load_averages \n";
        if ($loads[$loop] > 10) {
#                $loads[$loop] = 10;
        }
}

$polygon = new GD::Polygon;

$polygon->addPt (@origin);
for ($loop=1; $loop <= 9; $loop++) {
	$polygon->addPt ( $origin[0] + (25 * $loop), 
			  $origin[1] - ($loads[$loop-1] * 10)  );
}
$polygon->addPt (250 + $origin[0], $origin[1]);

$image->filledPolygon ($polygon, $red);
print $image->jpeg;

exit(0);
