28 Dec 2010 23:43:11 UTC
- Distribution: Flame-Palette
- Module version: 0.02
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (428 / 482 / 1)
- KwaliteeBus factor: 0
- 90.00% Coverage
- License: unknown
- Activity24 month
- Download (15.53KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
Flame::Palette - Perl extension to parse, unparse, create, process Flam3 palettes
use Flame::Palette; my $pal = Flame::Palette->new; $pal->set(index => 0, red => 255, green => 0, blue => 0); $pal->set(index => 127, red => 0, green => 255, blue => 0); $pal->set(index => 255, red => 0, green => 0, blue => 255); $pal->interpolate; $pal->unparse_xml(\*STDOUT);
This module provides a palette class, which knows these methods:
$pal = Flame::Palette->new
Constructor. Creates an empty palette, consisting of nothing
$pal->set(index => n, red => x, green => y, blue => z)
Set the entry whose number is n to the RGB values red=x, green=y, blue=z. All of those values have to be in the range 0...255
(red, green, blue) = $pal->get(index => n)
Retrieve the entry whose number is n. Returns an array in array context and an array reference otherwise. Returns black if the requested entry was not previously set.
Clear the existing palette and parse the XML file which is retrieved when reading the supplied stream. The XML file has to look like:
<palette> <color index="0" rgb="255 0 0" /> <!-- some entries are omitted --> <color index="255" rgb="0 0 255" /> </palette>
Trick: you can read from plain strings so you do not need to provide an actual file. Try this:
my $string; open(my $stream, '<', \$string); $pal->parse_xml($stream);
Do the same as the parse_xml() method, with the exception that the XML file must be a .flame one.
Dump the palette to an XML file. The stream doesn't have to be an open file, the trick shown above also works in the opposite direction:
my $string; open(my $stream, '>', \$string); $pal->unparse_xml($stream);
If the palette is sparse, e.g there are at least two entries with no other entires but space in between (similar to the sparse file concept of modern operating systems), the missing entries are interpolated from the entries around. Try the example shown at the top.
Remove all the existing entries.
Flam3 itself: http://www.flam3.com/
SVN: $Id: Palette.pm 125 2010-12-28 23:34:37Z daniel $
David Kroeber <email@example.com>
Copyright (C) 2010 by David Kroeber
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.2 or, at your option, any later version of Perl 5 you may have available.
Module Install Instructions
To install Flame::Palette, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Flame::Palette
For more information on module installation, please visit the detailed CPAN module installation guide.