Acme-POE-Tree

 view release on metacpan or  search on metacpan

lib/Acme/POE/Tree.pm  view on Meta::CPAN


	do_refresh($heap);

	return \@lights;
}

# Draw the star.  Also used to shimmer the star based on a moving
# "star cycle".

sub draw_star {
	my $heap = shift;

	my $center_y = $heap->{star_center_y};
	my $center_x = $heap->{star_center_x};
	my $cycle = $heap->{star_cycle};

	my $color_inner = $heap->{color_bg} | ($cycle % 2 ? A_DIM : A_BOLD);
	my $color_outer = $heap->{color_bg} | ($cycle % 2 ? A_BOLD : A_DIM);
	my $color_star  = $heap->{color_star} | ($cycle % 2 ? A_DIM : A_BOLD);

	attrset($color_star);
	addstr($center_y, $center_x, "O");

	attrset($color_inner);
	addstr($center_y - 1, $center_x - 1, "\\");
	addstr($center_y + 1, $center_x + 1, "\\");
	addstr($center_y - 1, $center_x + 1, "/");
	addstr($center_y + 1, $center_x - 1, "/");

	attrset($color_outer);
	addstr($center_y, $center_x - 1, "=");
	addstr($center_y, $center_x + 1, "=");
	addstr($center_y - 1, $center_x, "|");
	addstr($center_y + 1, $center_x, "|");

	attrset($color_inner);
	addstr($center_y, $center_x - 2, "-");
	addstr($center_y, $center_x + 2, "-");
	addstr($center_y - 2, $center_x, "|");
	addstr($center_y + 2, $center_x, "|");

	attrset($color_outer);
	addstr($center_y, $center_x - 3, "-");
	addstr($center_y, $center_x + 3, "-");
}

# Common refresh code.

sub do_refresh {
	my $heap = shift;

	attrset($heap->{color_bg});
	addstr(0, 0, "Press q to quit.");
	refresh();
}

# Common shutdown code.

sub _handle_shut_down {
	delete $_[HEAP]{console};
	$_[KERNEL]->delay("light_cycle", undef);
	$_[KERNEL]->delay("star_cycle", undef);
}

1;

__END__

=head1 NAME

Acme::POE::Tree - an animated christmas tree

=head1 SYNOPSIS

	perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()'

=head1 DESCRIPTION

Acme::POE::Tree uses IO::Tty to learn the current terminal size,
Curses to fill the terminal with a colorful Christmas tree, and POE to
animate the lights.

=head1 PUBLIC METHODS

=head2 new

Create a new Acme::POE::Tree application.  The light and star
animation delays may be set here.  The tree may also be set to exit
automatically after a short amount of time:

	use Acme::POE::Tree;
	my $tree = Acme::POE::Tree->new(
		{
			star_delay => 1.5,  # shimmer star every 1.5 sec
			light_delay => 2,   # twinkle lights every 2 sec
			run_for => 10,      # automatically exit after 10 sec
		}
	);
	$tree->run();

=head2 run

Run the tree until the user decides they've had enough.

=head1 AUTHOR

Rocco Caputo <rcaputo@cpan.org> with debugging and feedback from
irc.perl.org channel #poe.

=head1 BUG TRACKER

https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Acme-POE-Tree

=head1 REPOSITORY

http://github.com/rcaputo/acme-poe-tree

=head1 OTHER RESOURCES

http://search.cpan.org/dist/Acme-POE-Tree/

=head1 COPYRIGHT



( run in 2.593 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )