note 74806 deleted from function.imagefilledpolygon by tularis
| From: | tularis@php.net | Date: | Sat, 28 Apr 2007 08:40:15 +0000 |
| Subject: | note 74806 deleted from function.imagefilledpolygon by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125945@lists.php.net to get a copy of this message | ||
Note Submitter: satoru
Reason: useless
----
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);
?>