Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

JAPH attempt using Term::ANSIScreen

by atcroft (Monsignor)
on Jul 02, 2004 at 13:59 UTC ( #371396=obfuscated: 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.

Comment on JAPH attempt using Term::ANSIScreen
Download Code
Replies are listed 'Best First'.
Re: JAPH attempt using Term::ANSIScreen
by tbone1 (Monsignor) on Jul 02, 2004 at 14:13 UTC
    Aw heck, I just realized that I approved this for the SoPW area. Could one of the all-powerful members of Perlmonks move it to a more appropriate place? I apologize, I've spent all morning in Oracle Designer; it makes my brain hurt.

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://371396]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2015-07-30 12:17 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 (271 votes), past polls