Perl Advent Calendar 2008-12-25

Excited elfs

by Jerrad Pierce

As frequent readers of the calendar may have noticed, I'm a sucker for text-art and "ANSI-mation," so it's no surprise I bring you more text toys today. The author of Term::Animation, a library which provides facilities for sprite-based animation. With it he has produced "screensavers" like this weather monitor & aquarium, although one could produce all sorts of games too, or vingettes like our example:

mod25.pl

   1 use Term::Animation;
   2 use Curses;
   3 
   4 #You may need to disable color for lamer terminals
   5 (my $anim = Term::Animation->new)->color(1);
   6 
   7 #Build a snowman
   8 $anim->new_entity(
   9 		  position      => [25, 2, 10],
  10 		  shape         => do{ read(DATA, $_, 557); $_ },
  11 		  color         => do{ read(DATA, $_, 426); $_ }
  12 		 );
  13 #Discard comment
  14 seek(DATA, 49, 1);
  15 
  16 #Pack a projectile
  17 $snowball = [ do{ read(DATA, $_, 11); $_ }, do{ read(DATA, $_, 7); $_ } ];
  18 
  19 #Lob it
  20 $anim->new_entity(
  21 		  shape         => $snowball,
  22 		  position      => [-3, 6, 2],
  23 		  callback_args => [0, $anim->gen_path( 0,9,2,    #begin
  24 						       47,9,2,    #end
  25 						       [(0)x6,1], #change
  26 						       my $step=7)] );
  27 halfdelay(2);
  28 getch() && $anim->animate() for( 1..$step );
  29 sleep 3 && $anim->end();
  30 
  31 __DATA__
  32             .-~~\
  33            /     \ _
  34            ~x   .-~_)_
  35              ~x".-~   ~-.
  36          ,.  ( /         \   ,.
  37          ||   T  o  o     Y  ||
  38        ==:l   l   <       !  I;==
  39           \\   \  .__/   /  //
  40            \\ ,r"-,___.-'r.//
  41             }^ \.( )   _.'//.
  42            /    }~Xi--~  //  \
  43           Y    Y I\ \    "    Y
  44           |    | |o\ \        |
  45           |    l_l  Y T       |  -Row
  46           l      "o l_j       !
  47            \                 /
  48     ___,.---^.     o       .^---.._____
  49 "~~~          "           ~            ~~~"
  50             bbbbb
  51            b     b b
  52            bb   bbbbb
  53              bbb
  54          yy  b               yy
  55          yy      K  K        yy
  56        yyyy       Y          yyyy
  57           yy                yy
  58            yy  r rrrrrrr R yy
  59                RRR R  RRRRyy
  60                 RRRRRRR  yy
  61                R RR R  r
  62                R RKr R
  63                RRR  R R          KKKK
  64                  rK RRR
  65 
  66                    K             #Some terminals don't do light black
  67    _
  68 = (_)
  69  _
  70 (_|

See Also

Image::ANSIMation - Unfortunately incompatble with Term::Animation.

View Source (POD)