#!/usr/bin/perl

$size = 5;	# size of line

$x1 = $ARGV[0]; $y1 = $ARGV[1]; $x2 = $ARGV[2]; $y2 = $ARGV[3];
$r  = $ARGV[4]; $g  = $ARGV[5]; $b  = $ARGV[6];

$dx = $x2-$x1;		# the horizontal distance of the line
$dy = $y2-$y1;		# the vertical distance of the line
$dxabs = abs($dx);
$dyabs = abs($dy);
$sdx = sgn($dx);
$sdy = sgn($dy);
$x = $dyabs*2;
$y = $dxabs*2;
$px = $x1;		# current X pixel
$py = $y1;		# current Y pixel

if ($dxabs >= $dyabs) # the line is more horizontal than vertical
	{
	for($i=0;$i<$dxabs;$i++)
		{
		$y+=$dyabs;
		if ($y>=$dxabs)
			{
			$y-=$dxabs;
			$py+=$sdy;
			}
		$px+=$sdx;
		print "5,$px,$py,$size,$r,$g,$b\n";
		}
	}
else # the line is more vertical than horizontal
	{
	for($i=0;$i<$dyabs;$i++)
		{
		$x+=$dxabs;
		if ($x>=$dyabs)
			{
			$x-=$dyabs;
			$px+=$sdx;
			}
		$py+=$sdy;
		print "5,$px,$py,$size,$r,$g,$b\n";
		}
	}

sub sgn
{
if (@_[0] >  0) {return 1;}
if (@_[0] <  0) {return -1;}
if (@_[0] == 0) {return 0;}
}
