note 74806 added to function.imagefilledpolygon
| From: | satoru at osu1 dot php dot net | Date: | Fri, 27 Apr 2007 23:43:14 +0000 |
| Subject: | note 74806 added to function.imagefilledpolygon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125935@lists.php.net to get a copy of this message | ||
title: CONNECT POINTS
tested: with PHP 5.1.6, bundled GD 2.0.28 compatible
<?php
$thick = 20;
$points = array();
$points[] = array("x"=>-10, "y"=>300);
$points[] = array("x"=>100, "y"=>300);
$points[] = array("x"=>200, "y"=>100);
$points[] = array("x"=>200, "y"=>300);
$points[] = array("x"=>300, "y"=>100);
$points[] = array("x"=>300, "y"=>300);
$points[] = array("x"=>410, "y"=>300);
$image = imagecreate(400, 400);
$bg = imagecolorallocate($image, 248, 248, 248);
$color = array();
$color[] = imagecolorallocate($image, 0, 0, 0); // black
$color[] = imagecolorallocate($image, 0, 0, 255); // blue
$color[] = imagecolorallocate($image, 255, 0, 0); // red
$color[] = imagecolorallocate($image, 255, 0, 255); // magenta
$color[] = imagecolorallocate($image, 0, 255, 0); // green
$color[] = imagecolorallocate($image, 0, 255, 255); // cyan
$color[] = imagecolorallocate($image, 255, 255, 0); // yellow
$color[] = imagecolorallocate($image, 255, 255, 255); // white
$r = $thick / 2;
$num = 0;
// [CONNECT POINTS]
$p0 = array_shift($points);
foreach ($points as $p1) {
$num++;
imagefilledellipse($image, $p0["x"], $p0["y"], $thick, $thick,
$color[$num]);
imagefilledellipse($image, $p1["x"], $p1["y"], $thick, $thick,
$color[$num]);
if ($p0["x"] == $p1["x"]) {
$x = $p0["x"];
$corner = array(
$x+$r, $p0["y"],
$x-$r, $p0["y"],
$x-$r, $p1["y"],
$x+$r, $p1["y"]
);
}
else { // y = ax + b
$a = ($p1["y"]-$p0["y"]) / ($p1["x"]-$p0["x"]);
$b = $p0["y"] - ($a*$p0["x"]);
$rad = atan($a);
$sx = floor($r * sin($rad));
$sy = floor($r * cos($rad));
$corner = array(
$p0["x"]+$sx, ($a*$p0["x"] + $b)-$sy,
$p0["x"]-$sx, ($a*$p0["x"] + $b)+$sy,
$p1["x"]-$sx, ($a*$p1["x"] + $b)+$sy,
$p1["x"]+$sx, ($a*$p1["x"] + $b)-$sy
);
}
imagefilledpolygon($image, $corner, 4, $color[$num]);
$p0 = $p1;
}
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
----
Server IP: 61.195.146.164
Probable Submitter: 203.143.112.154
----
Manual Page -- http://www.php.net/manual/en/function.imagefilledpolygon.php
Edit -- https://master.php.net/note/edit/74806
Del: integrated -- https://master.php.net/note/delete/74806/integrated
Del: useless -- https://master.php.net/note/delete/74806/useless
Del: bad code -- https://master.php.net/note/delete/74806/bad+code
Del: spam -- https://master.php.net/note/delete/74806/spam
Del: non-english -- https://master.php.net/note/delete/74806/non-english
Del: in docs -- https://master.php.net/note/delete/74806/in+docs
Del: other reasons-- https://master.php.net/note/delete/74806
Reject -- https://master.php.net/note/reject/74806
Search -- https://master.php.net/manage/user-notes.php