search.cpan.org is shutting down
Kazuyoshi Tomita > Shape-RegularPolygon > Shape::RegularPolygon
Module Version: 0.01

# NAME

Shape::RegularPolygon - Object that treats the shape of the regular polygon

# SYNOPSIS

```  use Shape::RegularPolygon;

# Create a regular polygon
\$polygon = new Shape::RegularPolygon;
\$polygon->center(100, 50);
\$polygon->sides(3);
\$polygon->angle(3.14 / 6);

# By named parameter
\$polygon = new Shape::RegularPolygon(CenterX => 100,
CenterY =>  50,
Sides => 3,
Angle => 3.14 / 6);

# get vertexes
@points = \$polygon->points```

# DESCRIPTION

Shape::RegularPolygon is a class that treats the shape of the regular polygon. This object creates and returns vertex list of specified regular polygon.

# Construction

Simple construction
`  new Shape::RegularPolygon;`

When the parameter is omitted, the equilateral triangle is made in default. The parameter can be set later by using method.

Construction with named parameters
`  new Shape::RegularPolygon(named parameters);`

When you construct object, you can specify some parameters. See below about named parameters.

## Parameters

CenterX, CenterY

Position of regular polygon

Sides

Building n-sides polygon. When four is specified, square is made. It must be a value of three or more.

Angle

Rotate a polygon in radians (clockwise).

# METHODS

center(x, y)

Set position of polygon. Returns current position, when parameters are omitted.

```  \$shape->center(100, 200);
(\$x, \$y) = \$shape->center;```
sides(n)

Set the number of sides. Returns the number of sides, when parameters are omitted.

```  \$shape->sides(5);
\$n = \$shape->sides;```

```  \$shape->radius(100);

Set rotation angle. Returns current angle, when parameters are omitted. The rad is in radian. and clockwise.

```  \$shape->angle(3.14 / 6);      # 30 degree
points()

Returns vertexes list of polygon as follows.

```  (
{x => x0, y => y0},    # Vertex0
{x => x1, y => y1},    # Vertex1
:
:
)```

# Example

The following script builds png image file that regular pentagon was drawn.

``` #!/usr/bin/perl
use strict;
use warnings;
use Shape::RegularPolygon;
use GD;

my \$shape = new Shape::RegularPolygon;
\$shape->center(150, 100);
\$shape->sides(5);

my \$im = new GD::Image(300, 200);
\$im->fill(0, 0, \$im->colorAllocate(0xff, 0xff, 0xff));

my \$poly = new GD::Polygon;

\$im->filledPolygon(\$poly, \$im->colorAllocate(0x80, 0xe0, 0x80));

binmode STDOUT;
print \$im->png;```

None

# AUTHOR

Kazuyoshi Tomita, <kztomita@bit-hive.com>