NAME

Algorithm::Line::Bresenham - simple pixellated line-drawing algorithm

SYNOPSIS

use Algorithm::Line::Bresenham qw/line/;
my @points = line(3,3 => 5,0);
   # returns the list: [3,3], [4,2], [4,1], [5,0]
my @points = circle(30,30,5);
   # returns the points to draw a circle centered at 30,30, radius 5

DESCRIPTION

Bresenham is one of the canonical line drawing algorithms for pixellated grids. Given a start and an end-point, Bresenham calculates which points on the grid need to be filled to generate the line between them.

Googling for 'Bresenham', and 'line drawing algorithms' gives some good overview. The code here are adapted from various sources, mainly from C code at https://gist.github.com/bert/1085538

FUNCTIONS

line

line ($from_x, $from_y => $to_x, $to_y);

Generates a list of all the intermediate points. This is returned as a list of array references. Previous versions used to include a callback parameter as a CODE ref to act on each point in turn. This version omits that for performance reasons

circle

my @points = circle ($x, $y, $radius)

Returns the points to draw a circle centered on $x,$y with radius $radius

ellipse_rect

my @points = ellipse_rect ($x0, $y0, $x1, $y1)

Returns the points to an ellipse bound within a rectangle defined by the two coordinate pairs passed.

basic_bezier

my @points = basic_bezier ($x0, $y0, $x1, $y1, $x2, $y2)

This is not usefull on its own. Iteturns the points to segment of a bezier curve without a gradient sign change. It is a companion to the quad_bexier function that splits a bezier into segments with each gradient direction and these segments are computed in basic_bezier

basic_bezier

my @points = quad_bezier ($x0, $y0, $x1, $y1, $x2, $y2)

Draws a Bezier curve from ($x0,$y0) to ($x2,$y2) using control point ($x1,$y1)

TODO and BUGS

polylines nurbs arc line width fills pattern fills

THANKS

Patches for the circle algorithm and a float value bug contributed by Richard Clamp, thanks!

AUTHOR

osfameron, osfameron@cpan.org saiftynet

LICENSE

FreeBSD

INSTALLATION

Using cpan:

$ cpan Algorithm::Line::Bresenham

Manual install:

$ perl Makefile.PL
$ make
$ make install

1 POD Error

The following errors were encountered while parsing the POD:

Around line 336:

=cut found outside a pod block. Skipping to next block.