$splinekey = "<UL><LI>Green: original polygon or polyline<LI>Blue: control points added with addControlPoints()<LI>Black: spline generated by toSpline()</UL>";
if (1) {
use GD;
use GD::Polyline;
# create an image
$image = new GD::Image (500,300);
$white = $image->colorAllocate(255,255,255);
$black = $image->colorAllocate( 0, 0, 0);
$red = $image->colorAllocate(255, 0, 0);
# create a new polyline
$polyline = new GD::Polyline;
# add some points
$polyline->addPt( 0, 0);
$polyline->addPt( 0,100);
$polyline->addPt( 50,125);
$polyline->addPt(100, 0);
# polylines can use polygon methods (and vice versa)
SampleImage($image, "polyline-simple.png", "Simple", "GD::Polygon and GD::Polyline with same vertexes.</P>" . genHTMLTable([$summary_table], 1));
}
if (1) {
$image = NewImage();
$offset = 50;
for $poly (new GD::Polygon, new GD::Polyline) {
$poly->addPt( 0, 0);
$poly->addPt( 0,100);
$poly->addPt( 50,125);
$poly->addPt(100, 0);
$poly->offset(50 + $offset,80);
$offset += 200;
# draw the original poly
$image->polydraw($poly,$green);
# create and draw the control line for the spline
$ctrlline = $poly->addControlPoints();
$image->polydraw($ctrlline,$cyan);
# create and draw the spline itself
$spline = $ctrlline->toSpline();
$image->polydraw($spline,$black);
}
SampleImage($image, "polyline-spline.png", "Spline", "Splines fit to vertices of polygon and polyline. $splinekey");
}
if (1) {
$image = NewImage();
$triangle = new GD::Polygon;
$triangle->addPt( 0, 0);
$triangle->addPt(-19, 95);
$triangle->addPt( 19, 95);
$triangle->offset(250,50);
foreach (1..9) {
$image->polydraw($triangle,gdBrushed);
$triangle->rotate($TWO_PI / 9, 250, 150);
}
SampleImage($image, "polyline-star9.png", "Nine Pointed Star", "A triangle, rotated about a point other than the origin.<BR>Demonstration of \$poly->rotate() and \$poly->offset()");
}
if (1) {
$image = NewImage();
$cloverControl = new GD::Polyline;
$cloverControl->addPt(45,45);
$cloverControl->addPt(10,10);
$cloverControl->addPt(90,10);
$cloverControl->addPt(55,45);
$cloverControl->addPt(90,10);
$cloverControl->addPt(90,90);
$cloverControl->addPt(55,55);
$cloverControl->addPt(90,90);
$cloverControl->addPt(10,90);
$cloverControl->addPt(45,55);
$cloverControl->addPt(10,90);
$cloverControl->addPt(10,10);
$cloverControl->addPt(45,45);
$clover = $cloverControl->toSpline();
# note that the three following transformations
# could have been called on $cloverControl, instead,
# followed by the above call
$clover->offset($clover->centroid(-1));
$clover->scale(3, 3);
$clover->offset(250, 150);
$image->filledPolygon($clover,$green);
SampleImage($image, "polyline-clover.png", "Clover", "Sample image generated by GD::Polygon");
}
if (1) {
$image = NewImage();
$polyline = new GD::Polyline;
for (0..15) {
$polyline->addPt(30 * $_ + 10, rand(90) + 5);
}
$image->polyline($polyline,$green);
$ctrlline = $polyline->addControlPoints();
$ctrlline->offset(0,100);
$image->polyline($ctrlline,$cyan);
$spline = $ctrlline->toSpline();
$spline->offset(0,100);
$image->polyline($spline,$black);
SampleImage($image, "polyline-zigzag.png", "Zigzag", "Spline fit to random function. $splinekey");