12 Nov 2006 11:03:58 UTC
- Distribution: Algorithm-Line-Bresenham
- Module version: 0.11
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (606 / 0 / 0)
- KwaliteeBus factor: 1
- 98.78% Coverage
- License: perl_5
- Perl: v5.6.1
- Download (2.85KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:2 non-PAUSE users
Why not adopt me?This distribution is up for adoption! If you're interested then please contact the PAUSE module admins via email.
Algorithm::Line::Bresenham - simple pixellated line-drawing algorithm
use Algorithm::Line::Bresenham qw/line/; my @points = line(3,3 => 5,0); # returns the list: [3,3], [4,2], [4,1], [5,0] line(3,3 => 5,0, \&draw_line); # calls draw_line on each point in turn
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 takes its starting point from Mark Feldman's Pascal code in his article Bresenham's Line and Circle Algorithms at http://www.gamedev.net/reference/articles/article767.asp.
line ($from_y, $from_x => $to_y, $to_x);
Generates a list of all the intermediate points. This is returned as a list of array references.
line ($from_y, $from_x => $to_y, $to_x, \&callback);
Calls the referenced function on each point in turn. The callback could be used to actually draw the point. Returns the collated return values from the callback.
my @points = circle ($y, $x, $radius)
Returns the points to draw a circle with
Patches for the circle algorithm and a float value bug contributed by Richard Clamp, thanks!
Copyright (c) 2004-2006 osfameron. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Algorithm::Line::Bresenham, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Algorithm::Line::Bresenham
For more information on module installation, please visit the detailed CPAN module installation guide.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|