NAME
Imager::Draw::Hexagon - Draw hexes easily using Imager
VERSION
version 0.0102
SYNOPSIS
use Imager::Draw::Hexagon;
my $hex = Imager::Draw::Hexagon->new( image => $image, side_length => 100 );
$hex->draw(color => 'blue');
DESCRIPTION
Drawing hexagons requires calculating all the points in the hex. It's harder than it sounds. I figured since I was solving it, I might as well solve it for everyone, so this module was born.
METHODS
new(image => $image, side_length => 100)
Constructor.
- image
-
The Imager object to draw the hex on to. Required.
- side_length
-
The length of each side of the hexagon in pixels. Required.
- x
-
The x coordinate of the top left corner to start drawing the hex. Defaults to 0.
- y
-
The y coordinate of the top left corner to start drawing the hex. Defaults to 0.
x()
Get or set the x coordinate of the top left corner of where to start drawing the hex.
y()
Get or set the y coordinate of the top left corner of where to start drawing the hex.
image()
Get or set the Imager object.
side_length()
Get or set the length, in pixels, of each side of the hex.
short_leg()
Hexes are essentially a square with a series of right trangles drawn around them. This is the short leg of that triangle or half the value of the side length.
long_leg()
Hexes are essentially a square with a series of right trangles drawn around them. This is the long leg of that triangle or the side length multiplied by 0.866 (sin(60)).
ew_coords()
Returns an array ref of coordinent pairs if the hex is to be drawn with a flat top (east-west).
ns_coords()
Returns an array ref of coordinent pairs if the hex is to be drawn with a peaked top (north-south).
outline()
Call this to draw an outline of a hex on the image. It accepts all the same parameters as "polyline" in Imager::Draw, plus:
- direction
-
Defaults to
ew
. Options areew
andns
.
draw()
Call this to draw a filled hex on the image. It accepts all the same parameters as "polygon" in Imager::Draw, plus:
- direction
-
Defaults to
ew
. Options areew
andns
.
TODO
None that I can think of at this time.
PREREQS
SUPPORT
AUTHOR
LEGAL
Imager::Draw::Hexagon is Copyright 2014 Plain Black Corporation (http://www.plainblack.com) and is licensed under the same terms as Perl itself.