Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found