Image::ANSI::Palette - A base class palettes


Image-ANSI documentation Contained in the Image-ANSI distribution.

Index


Code Index:

NAME

Top

Image::ANSI::Palette - A base class palettes

SYNOPSIS

Top

	# use Image::ANSI::Palette::VGA or your own
	$pal = Image::ANSI::Palette:VGA->new;

METHODS

Top

new( [$palette] )

Creates a new Image::ANSI::Palette object.

get( $index )

Get the rgb triple at index $index

set( $index, $rgb )

Write an rgb triple at index $index

clear( )

Clears any in-memory data.

colors( )

General accessor to the palette of colors

AUTHOR

Top

* Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-ANSI documentation Contained in the Image-ANSI distribution.
package Image::ANSI::Palette;

use strict;
use warnings;

our $VERSION = '0.10';

sub new {
	my $class   = shift;
	my $palette = shift;
	my $self    = {};

	bless $self, $class;

	$self->clear;

	if( $palette ) {
		for( 0..@$palette - 1 ) {
			$self->set( $_, $palette->[ $_ ] );
		}
	}

	return $self;
}

sub get {
	my $self  = shift;
	my $index = shift;

	return $self->{ data }->[ $index ]; 
}

sub set {
	my $self = shift;
	my ( $index, $rgb ) = @_;

	$self->{ data }->[ $index ] = $rgb; 
}

sub clear {
	my $self = shift;

	$self->{ data } = [];
}

sub colors {
	my $self = shift;

        $self->{ data } = $_[ 0 ] if @_;

	return $self->{ data };
}

1;