Image::TextMode::Animation - A base class for text mode animation file formats


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

Index


Code Index:

NAME

Top

Image::TextMode::Animation - A base class for text mode animation file formats

DESCRIPTION

Top

This class should be used for any format that requires a sequence of frames for display.

ACCESSORS

Top

* frames - an arrayref of frame objects

METHODS

Top

new( %args )

Creates a new instance.

add_frame( $frame )

Adds a frame to the end of the array.

width( )

Returns the largest frame width.

height( )

Returns the largest frame height.

dimensions( )

Returns the a list containing the values of width and height.

as_ascii( )

Returns all of the text from all of the frames.

PROXIED METHODS

Top

The following methods are proxies to the last element in frames.

* getpixel
* getpixel_obj
* putpixel
* clear_screen
* clear_line

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-TextMode documentation Contained in the Image-TextMode distribution.
package Image::TextMode::Animation;

use Moose;
use Symbol ();

BEGIN {
    for my $sub (
        qw( getpixel getpixel_obj putpixel clear_screen clear_line ) )
    {
        *{ Symbol::qualify_to_ref( __PACKAGE__ . "\::$sub" ) } = sub {
            shift->frames->[ -1 ]->$sub( @_ );
            }
    }
}

has 'frames' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );

sub add_frame {
    my ( $self, $frame ) = @_;
    push @{ $self->frames }, $frame;
}

sub width {
    my $self = shift;
    my @widths = sort { $b <=> $a } map { $_->width } @{ $self->frames };
    return $widths[ 0 ];
}

sub height {
    my $self = shift;
    my @heights = sort { $b <=> $a } map { $_->height } @{ $self->frames };
    return $heights[ 0 ];
}

sub dimensions {
    my $self = shift;
    return $self->width, $self->height;
}

sub as_ascii {
    my $self = shift;
    return join( "\n", map { $_->as_ascii } @{ $self->frames } );
}

no Moose;

__PACKAGE__->meta->make_immutable;

1;