JT Smith
and 1 contributors

# NAME

Imager::Draw::Hexagon - Draw hexes easily using Imager

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 are `ew` and `ns`.

## 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 are `ew` and `ns`.

# TODO

None that I can think of at this time.

# SUPPORT

Repository

http://github.com/rizen/Imager-Draw-Hexagon

Bug Reports

http://github.com/rizen/Imager-Draw-Hexagon/issues

# AUTHOR

JT Smith <jt_at_plainblack_dot_com>