note 98191 deleted from function.imageline by thiago
[email protected] Mon, 31 May 2010 21:15:18 -0700
Newsgroups
php.notes
Message-ID
<[email protected] >
Note Submitter: allenn at hot dot ee
----
Function drawing of a line by a brush uses midpoint circle algorithm..., if dullness I agree to remove :)))
<?php
//function drawLine(resource$image,int $x0,int $y0,int $x1,int $y1,int $lineWidth,int $color)
function drawLine($image,$x0, $y0,$x1, $y1,$radius,$color)
{
$f = 1 - $radius;
$ddF_x= 1;
$ddF_y = -2 * $radius;
$x= 0;
$y = $radius;
imageline($image,$x0, $y0 + $radius,$x1, $y1 + $radius,$color);
imageline($image,$x0, $y0 - $radius,$x1, $y1 - $radius,$color);
imageline($image,$x0 + $radius, $y0,$x1 + $radius, $y1,$color);
imageline($image,$x0 - $radius, $y0,$x1 - $radius, $y1,$color);
while($x< $y)
{
if($f >= 0)
{
$y--;
$ddF_y += 2;
$f += $ddF_y;
}
$x++;
$ddF_x+= 2;
$f += $ddF_x;
imageline($image,$x0 + $x, $y0 + $y,$x1 + $x, $y1+ $y,$color);
imageline($image,$x0 - $x, $y0 + $y,$x1 - $x, $y1 + $y,$color);
imageline($image,$x0 + $x, $y0 - $y,$x1 + $x, $y1 - $y,$color);
imageline($image,$x0 - $x, $y0 - $y,$x1 - $x, $y1 - $y,$color);
imageline($image,$x0 + $y, $y0 + $x,$x1 + $y, $y1 + $x,$color);
imageline($image,$x0 - $y, $y0 + $x,$x1 - $y, $y1 + $x,$color);
imageline($image,$x0 + $y, $y0 - $x,$x1 + $y, $y1 - $x,$color);
imageline($image,$x0 - $y, $y0 - $x,$x1 - $y, $y1 - $x,$color);
}
}
header ('Content-type: image/png');
$img = imagecreatetruecolor(600,600);
$col = imagecolorallocate($img,0,255,252);
//use the function
rasterCircle($img,50, 50,540,540,40,$col);
imagepng($img);
imagedestroy($img);
?>