note 46275 added to function.imagesetpixel
| From: | odin dtdm . org | Date: | Tue, 05 Oct 2004 12:36:39 +0000 |
| Subject: | note 46275 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78023@lists.php.net to get a copy of this message | ||
Just a simple implementation of the Bresenham algorythm (educational purpose....)
You can find more about this and many other tutorials for gfx there: http://brand107.home.comcast.net/pc-gpe/
<?php
/****************************************************
Bresenham Line Algorythm PHP/GD implementation
****************************************************/
function line($im,$x1,$y1,$x2,$y2,$color){
$deltax=abs($x2-$x1);
$deltay=abs($y2-$y1);
if ($deltax>$deltay) {
$numpixels=$deltax+1;
$d=(2*$deltay)-$deltax;
$dinc1=$deltay << 1; $dinc2=($deltay-$deltax) << 1;
$xinc1=1; $xinc2=1;
$yinc1=0; $yinc2=1;
} else {
$numpixels=$deltay+1;
$d=(2*$deltax)-$deltay;
$dinc1=$deltax << 1; $dinc2=($deltax-$deltay)<<1;
$xinc1=0; $xinc2=1;
$yinc1=1; $yinc2=1;
}
if ($x1>$x2) {
$xinc1=-$xinc1;
$xinc2=-$xinc2;
}
if ($y1>$y2) {
$yinc1=-$yinc1;
$yinc2=-$yinc2;
}
$x=$x1;
$y=$y1;
for ($i=0;$i<$numpixels;$i++) {
imagesetpixel($im,$x,$y,$color);
if ($d<0) {
$d+=$dinc1;
$x+=$xinc1;
$y+=$yinc1;
} else {
$d+=$dinc2;
$x+=$xinc2;
$y+=$yinc2;
}
}
return ;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46275
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46275&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46275&report=yes
Search -- http://master.php.net/manage/user-notes.php