Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Do you know where your variables are?
 
PerlMonks  

JAPH attempt using Term::ANSIScreen - redux

by atcroft (Monsignor)
on Jan 28, 2007 at 00:15 UTC ( #596923=obfuscated: print w/ replies, xml ) Need Help??

Approximately 2.5 years ago, I posted JAPH attempt using Term::ANSIScreen, my first attempt at a JAPH-like program. A few days ago, I decided to take a second look at it, to see what I could do. Here it is, for your enjoyment. (The behavior is the same as described with the previous posting.) Comments welcome (but since golfing is not my specialty, please don't kill(TERM, me)...)

#!/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 (@characterline); while ( my $line = <DATA> ) { my @parts = ( $line =~ m/(.{5})/g ); foreach my $s (@parts) { my @pieces = ( substr( $s, 0, 1 ), hex( substr( $s, 1, 2 ) ), hex( substr( $s, 3, 2 ) ) ); my $res = resolve( $pieces[2] ); $letters{ $pieces[0] }[ $pieces[1] ] = $res; } } { 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; } } } sub obscure { my ($coor_ref) = @_; my $digit = $coor_ref->{y} * 8 + $coor_ref->{x}; return $digit; } sub resolve { my ($digit) = @_; my %coor = ( x => ( $digit % 8 ), y => int( $digit / 8 ) ); return \%coor; } __DATA__ 0000 0101 0202 0303 0404 0505 0606 0708 0809 090a 0a0b 0b0c 0c0d 0d0e 0e10 0f11 1012 1113 1214 1315 1416 1518 1619 171a 181b 191c 1a1d 1b1e 1c20 1d21 1e22 1f23 2024 2125 2226 2328 2429 252a 262b 272c 282d 292e 2a30 2b31 2c32 2d33 2e34 2f35 3036 3138 3239 333a 343b 353c 363d 373eJ0002J0103J0204J0305 J0406J050cJ060dJ0714J0815J091cJ0a1dJ0b24J0c25J0d29J0e2aJ0f2c J102dJ1132J1233J1334a0011a0112a0213a0314a0415a051da061ea0728 a0829a092da0a2ea0b21a0c22a0d23a0e25a0f26a1031a1132a1233a1335 a1436c0012c0113c0214c0332c0433c0534c0618c0719c0820c0921c0a28 c0b29e0011e0112e0213e0314e0418e0519e061ce071de0820e0921e0a22 e0b23e0c24e0d25e0e28e0f29e1031e1132e1233e1334e1435h0000h0101 h0208h0309h0410h0511h0618h0719h081ah091bh0a1ch0b20h0c21h0d24 h0e25h0f28h1029h112ch122dh1330h1431h1534h1635k0000k0101k0208 k0309k0420k0521k0622k0723k0824k0910k0a11k0b14k0c15k0d18k0e19 k0f1bk101ck1128k1229k132bk142ck1530k1631k1734k1835l0009l010a l0211l0312l0419l051al0621l0722l0829l092al0a00l0b01l0c02l0d03 l0e32l0f33l1034n0018n011an021bn031cn041dn0520n0621n0725n0826 n0928n0a29n0b2dn0c2en0d30n0e31n0f35n1036o0012o0113o0214o0332 o0433o0534o0618o0719o081do091eo0a20o0b21o0c25o0d26o0e28o0f29 o102do112ep0010p0111p0213p0314p0415p0528p0629p072bp082cp092d p0a18p0b19p0c1ap0d1ep0e20p0f21p1022p1126p1230p1331p1438p1539 r0010r0112r0213r0314r0415r0518r0619r071dr081er0920r0a21r0b28 r0c29r0d30r0e31s0010s0111s0212s0313s0414s0520s0621s0722s0823 s0924s0a30s0b31s0c32s0d33s0e34s0f18s1019s112cs122dt0012t0113 t0222t0323t042at052bt0618t0719t081at091bt0a1ct0b1dt0c33t0d34 t0e35u0018u0119u021cu031du0420u0521u0624u0725u0828u0929u0a2c u0b2du0c31u0d32u0e33u0f35

Update 2007-01-27: Noticed that I could remove a line dealing with the results of the resolve function.

Update 2007-01-27: Removed reference to Data::Dumper, that was used while playing with the code earlier.

Comment on JAPH attempt using Term::ANSIScreen - redux
Select or Download Code
Re: JAPH attempt using Term::ANSIScreen - redux
by atcroft (Monsignor) on Jan 28, 2007 at 01:01 UTC

    I realized that I was doing way too much in the open, so playing around with the encoding mechanism I had gave me the following code (presented here, for your enjoyment).

    #!/usr/bin/perl -w use strict; use Term::ANSIScreen; $| = 1; my %config = ( delay => 0.1, width => 75, looptimes => 10 ); my (@characterline); foreach my $i ( 0 .. 8 ) { push @characterline, ' ' x 226; } while ( my $line = <DATA> ) { while ( $line =~ m/(.)(.)(.{2})/g ) { substr( $characterline[ hex($2) ], hex($3), 1, $1 ); } } my $console = Term::ANSIScreen->new; { $console->Cls(); foreach my $i ( 0 .. ( $config{looptimes} - 1 ) ) { foreach my $x ( 0 .. length( $characterline[0] ) ) { $console->Cursor( 1, 1 ); foreach my $y ( 0 .. $#characterline ) { print substr( $characterline[$y] x 2, $x, $config{width} ), "\n"; } select undef, undef, undef, $config{delay}; } } } __DATA__ J002J003J004J005J006h051h052l090l091l092l093h0a2h0a3k0bdk0beJ104 J105h151h152l191l192h1a2h1a3k1bdk1beJ204J205s212s213s214s215s216 t21dt21ea22ea22fa230a231a232o241o242o243t24at24bh251h252e25be25c e25de25er263r265r266r267r268p275p276p278p279p27ae27fe280e281e282 r287r289r28ar28br28cl291l292h2a2h2a3a2aca2ada2aea2afa2b0c2b6c2b7 c2b8k2bdk2bek2c1k2c2e2c7e2c8e2c9e2car2cfr2d1r2d2r2d3r2d4J304J305 u309u30au30du30es312s313t31bt31ct31dt31et31ft320a332a333n336n338 n339n33an33bo33fo340o344o345t348t349t34at34bt34ct34dh351h352h353 h354h355e35ae35be35ee35fr363r364r368r369p375p376p377p37be37ee37f e382e383r387r388r38cr38dl391l392h3a2h3a3h3a4h3a5h3a6a3b0a3b1c3b4 c3b5k3bdk3bek3c0k3c1e3c6e3c7e3cae3cbr3cfr3d0r3d4r3d5J404J405u409 u40au40du40es412s413s414s415s416t41dt41ea42ea42fa430a432a433n436 n437n43bn43co43fo440o444o445t44at44bh451h452h455h456e45ae45be45c e45de45ee45fr463r464p475p476p477p47be47ee47fe480e481e482e483r487 r488l491l492h4a2h4a3h4a6h4a7a4aca4ada4aea4b0a4b1c4b4c4b5k4bdk4be k4bfk4c0k4c1e4c6e4c7e4c8e4c9e4cae4cbr4cfr4d0J501J502J504J505u509 u50au50du50es516s517t51dt51ea52da52ea532a533n536n537n53bn53co53f o540o544o545t54at54bh551h552h555h556e55ae55br563r564p575p576p578 p579p57ae57ee57fr587r588l591l592h5a2h5a3h5a6h5a7a5aba5aca5b0a5b1 c5b4c5b5k5bdk5bek5c0k5c1e5c6e5c7r5cfr5d0J602J603J604u60au60bu60c u60es612s613s614s615s616t61et61ft620a62ea62fa630a632a633n636n637 n63bn63co641o642o643t64bt64ct64dh651h652h655h656e65be65ce65de65e e65fr663r664p675p676e67fe680e681e682e683r687r688l692l693l694h6a2 h6a3h6a6h6a7a6aca6ada6aea6b0a6b1c6b6c6b7c6b8k6bdk6bek6c1k6c2e6c7 e6c8e6c9e6cae6cbr6cfr6d0p775p776

    Update 2007-01-27: Removed one configuration and one left-over variable. Placed remaining three into a single hash, and updated code to use hash. Updated loop to prepare @characterline array. Updated loop to use the number of items in @characterline.

    Update 2007-01-27: Changed routine loading from DATA to use a regex rather than multiple substr() calls.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (17)
As of 2014-04-16 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (428 votes), past polls