Name

toPt( ) — define a polygon’s vertices using relative coordinates

Synopsis

GD::Polygon::toPt(dx, dy)

This method will allow you to specify the points of a polygon relative to a starting point, just like Logo-type turtle graphics. Use addPt( ) to define the first point in the polygon, then subsequent calls to toPt( ) will create new points by adding the dx and dy parameters to the x and y values of the previous point. Note that the polygon object still stores only the absolute values of the coordinates, so getPt( ) will return the same value as if you had added the point with addPt( ).

To draw a parallelogram whose vertices are at (10, 10), (20, 20), (30, 20), and (20, 10), use:

my $parallelogram = new GD::Polygon;       # create a new polygon
$parallelogram->addPt(10, 10);             # add the first point
$poly->toPt(10, 10);                       # add (20, 20)
$poly->toPt(10, 0);                        # add (30, 20)
$poly->toPt(-10, -10);                     # add (20, 10)
$image->polygon($parallelogram, $black);   # draw the polygon in black

Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.