Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

My obligatory first attempt at a JAPH, so I'd welcome comment and/or constructive critique. I do not really consider it obfu; thus my confusion on where to post it, since Obfuscations did not seem quite right. (If there is a better place to move it to, please suggest it. Thank you.)

Basic process is as follows. In attempting not to use the words themselves, I created a hash containing the positions of the letters appearing in the words. I then created a hash containing a mapping of character positions for drawing each character (thus its length). I then built each line's display, and began to loop, writing only a specified length segment of the lines each time, and using Term::ANSIScreen to move back to the beginning so it would appear somewhat "animated".

Enjoy.

#!/usr/bin/perl -w use strict; use Term::ANSIScreen; $| = 1; my $delay = 0.1; my $width = 75; my $charwidth = 9; my $looptimes = 10; my %lpos = ( ' ' => [ 4, 12, 17, 24 ], 'a' => [ 5, 19 ], 'c' => [20], 'e' => [ 10, 14, 22 ], 'h' => [ 9, 18 ], 'J' => [0], 'k' => [21], 'l' => [16], 'n' => [6], 'o' => [7], 'p' => [13], 'r' => [ 11, 15, 23 ], 's' => [2], 't' => [ 3, 8 ], 'u' => [1] ); my (%letters); { my ($x); my ($y); foreach $y ( 0 .. 7 ) { foreach $x ( 0 .. 6 ) { push( @{ $letters{' '} }, { 'x' => $x, 'y' => $y } ); } } foreach $x ( 1 .. 5 ) { push( @{ $letters{'a'} }, { 'x' => $x, 'y' => 2 } ); } foreach $x ( 5 .. 6 ) { push( @{ $letters{'a'} }, { 'x' => $x, 'y' => 3 } ); } foreach $x ( 0 .. 1, 5 .. 6 ) { push( @{ $letters{'a'} }, { 'x' => $x, 'y' => 5 } ); } foreach $y ( 4, 6 ) { foreach $x ( 1 .. 3, 5 .. 6 ) { push( @{ $letters{'a'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 2, 6 ) { foreach $x ( 2 .. 4 ) { push( @{ $letters{'c'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 3 .. 5 ) { foreach $x ( 0 .. 1 ) { push( @{ $letters{'c'} }, { 'x' => $x, 'y' => $y } ); } } foreach $x ( 1 .. 4 ) { push( @{ $letters{'e'} }, { 'x' => $x, 'y' => 2 } ); } foreach $x ( 0 .. 1, 4 .. 5 ) { push( @{ $letters{'e'} }, { 'x' => $x, 'y' => 3 } ); } foreach $x ( 0 .. 5 ) { push( @{ $letters{'e'} }, { 'x' => $x, 'y' => 4 } ); } foreach $x ( 0 .. 1 ) { push( @{ $letters{'e'} }, { 'x' => $x, 'y' => 5 } ); } foreach $x ( 1 .. 5 ) { push( @{ $letters{'e'} }, { 'x' => $x, 'y' => 6 } ); } foreach $y ( 0 .. 2 ) { push( @{ $letters{'h'} }, { 'x' => 0, 'y' => $y }, { 'x' => 1, 'y' => $y } ); } foreach $x ( 0 .. 4 ) { push( @{ $letters{'h'} }, { 'x' => $x, 'y' => 3 } ); } foreach $y ( 4 .. 6 ) { foreach $x ( 0 .. 1, 4 .. 5 ) { push( @{ $letters{'h'} }, { 'x' => $x, 'y' => $y } ); } } foreach $x ( 2 .. 6 ) { push( @{ $letters{'J'} }, { 'x' => $x, 'y' => 0 } ); } foreach $y ( 1 .. 4 ) { push( @{ $letters{'J'} }, { 'x' => 4, 'y' => $y }, { 'x' => 5, 'y' => $y } ); } foreach $x ( 1 .. 2, 4 .. 5 ) { push( @{ $letters{'J'} }, { 'x' => $x, 'y' => 5 } ); } foreach $x ( 2 .. 4 ) { push( @{ $letters{'J'} }, { 'x' => $x, 'y' => 6 } ); } foreach $y ( 0 .. 1 ) { push( @{ $letters{'k'} }, { 'x' => 0, 'y' => $y }, { 'x' => 1, 'y' => $y } ); } foreach $x ( 0 .. 4 ) { push( @{ $letters{'k'} }, { 'x' => $x, 'y' => 4 } ); } foreach $y ( 2 .. 3 ) { foreach $x ( 0 .. 1, 6 - $y .. 7 - $y ) { push( @{ $letters{'k'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 5 .. 6 ) { foreach $x ( 0 .. 1, $y - 2 .. $y - 1 ) { push( @{ $letters{'k'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 1 .. 5 ) { push( @{ $letters{'l'} }, { 'x' => 1, 'y' => $y }, { 'x' => 2, 'y' => $y } ); } foreach $x ( 0 .. 3 ) { push( @{ $letters{'l'} }, { 'x' => $x, 'y' => 0 } ); } foreach $x ( 2 .. 4 ) { push( @{ $letters{'l'} }, { 'x' => $x, 'y' => 6 } ); } foreach $x ( 0, 2 .. 5 ) { push( @{ $letters{'n'} }, { 'x' => $x, 'y' => 3 } ); } foreach $y ( 4 .. 6 ) { foreach $x ( 0 .. 1, 5 .. 6 ) { push( @{ $letters{'n'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 2, 6 ) { foreach $x ( 2 .. 4 ) { push( @{ $letters{'o'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 3 .. 5 ) { foreach $x ( 0 .. 1, 5 .. 6 ) { push( @{ $letters{'o'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 2, 5 ) { foreach $x ( 0 .. 1, 3 .. 5 ) { push( @{ $letters{'p'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 3 .. 4 ) { foreach $x ( 0 .. 2, 6 ) { push( @{ $letters{'p'} }, { 'x' => $x, 'y' => $y } ); } } foreach $y ( 6 .. 7 ) { push( @{ $letters{'p'} }, { 'x' => 0, 'y' => $y }, { 'x' => 1, 'y' => $y } ); } foreach $x ( 0, 2 .. 5 ) { push( @{ $letters{'r'} }, { 'x' => $x, 'y' => 2 } ); } foreach $x ( 0 .. 1, 5 .. 6 ) { push( @{ $letters{'r'} }, { 'x' => $x, 'y' => 3 } ); } foreach $y ( 4 .. 6 ) { push( @{ $letters{'r'} }, { 'x' => 0, 'y' => $y }, { 'x' => 1, 'y' => $y } ); } foreach $y ( 2, 4, 6 ) { foreach $x ( 0 .. 4 ) { push( @{ $letters{'s'} }, { 'x' => $x, 'y' => $y } ); } } foreach $x ( 0 .. 1 ) { push( @{ $letters{'s'} }, { 'x' => $x, 'y' => 3 } ); } foreach $x ( 4 .. 5 ) { push( @{ $letters{'s'} }, { 'x' => $x, 'y' => 5 } ); } foreach $y ( 2, 4 .. 5 ) { foreach $x ( 2 .. 3 ) { push( @{ $letters{'t'} }, { 'x' => $x, 'y' => $y } ); } } foreach $x ( 0 .. 5 ) { push( @{ $letters{'t'} }, { 'x' => $x, 'y' => 3 } ); } foreach $x ( 3 .. 5 ) { push( @{ $letters{'t'} }, { 'x' => $x, 'y' => 6 } ); } foreach $y ( 3 .. 5 ) { foreach $x ( 0 .. 1, 4 .. 5 ) { push( @{ $letters{'u'} }, { 'x' => $x, 'y' => $y } ); } } foreach $x ( 1 .. 3, 5 ) { push( @{ $letters{'u'} }, { 'x' => $x, 'y' => 6 } ); } } my (@characterline); { my (@s); { foreach my $k ( keys(%lpos) ) { foreach my $i ( @{ $lpos{$k} } ) { $s[$i] = $k; } } } my (@characterblock); foreach my $y ( 0 .. 8 ) { foreach my $x ( 0 .. ( scalar(@s) * $charwidth ) ) { $characterblock[$y][$x] = ' '; } } my $x = 0; foreach my $l (@s) { foreach my $i ( 0 .. $#{ $letters{$l} } ) { $characterblock[ $letters{$l}[$i]{'y'} ] [ $x + $letters{$l}[$i]{'x'} ] = $l; } $x += $charwidth; } foreach my $y ( 0 .. 8 ) { $characterline[$y] = join( '', @{ $characterblock[$y] } ); } } my $console = Term::ANSIScreen->new; { $console->Cls(); foreach my $i ( 0 .. ( $looptimes - 1 ) ) { foreach my $x ( 0 .. length( $characterline[0] ) ) { $console->Cursor( 1, 1 ); foreach my $y ( 0 .. 8 ) { print substr( $characterline[$y] x 2, $x, $width ), "\n"; } select undef, undef, undef, $delay; } } }

Update: (02-Jul-2004) Changed looping to be configurable.


In reply to JAPH attempt using Term::ANSIScreen by atcroft

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (10)
    As of 2015-07-28 09:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (254 votes), past polls