Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

The Matrix Reloaded: JAPH

by davido (Cardinal)
on Sep 01, 2003 at 22:14 UTC ( #288199=obfuscated: print w/replies, xml ) Need Help??

The Matrix has now been reloaded with Perl hackers.

This JAPH is set to work best on screens of 70 columns or more. If you have fewer than 70 cols., I left the adjustment easy to find.

This JAPH has tested successfully on Unix, Linux, and Win98.

Once you see what it does, walking through it probably won't be too awfully tricky, but post any comments or suggestions so that I can learn something too. Let me know what you think!

Here's the code. Prepare yourself to enter the Matrix.

map{my$qw;map{!$q[$_]&&rand>.993?do{$q[$_]=${[qw$Just another Perl hacker$]}[$qq++].q$.$x5 .q$ $x5;$qq=$qq>3?0:$qq}:0;$q[$_]?do{($qx, $q[$_])=split//,$q[$_],2;$qw.=$qx}:{$qw.=q$ $}}1..70;;print$qw,$/; select$a,$a,$a,.06}1..300



"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: The Matrix Reloaded: JAPH
by cfreak (Chaplain) on Sep 02, 2003 at 14:42 UTC

    davido++! very nice. I was working on something like this but never got around to finishing it. Too bad because I knew that someone would do it eventually :)

    Something that you might be able to add: if the terminal supports it you can add the correct escape sequences to get some green color like so:

    # there may be some others but these are the ones I know of if($ENV{TERM} =~ /linux|xterm|xterm-color|vt220|ansi/) { $color = 1; } # assuming $char is the character you are about to print $char = "\33[0;32m$char\33[0m" if $color;

    \33[ is the escape 0;<nn>m is the color (32 is green 30 - 39 seem to be the only ones that work) the \33[0m at the end returns it to the default white.

    Hope you find that interesting :)

    Lobster Aliens Are attacking the world!
      in Windows 2000 you can use the line
      system ("color 0A");
      to turn the color to black background, green foreground.
        You mean black bg and green fg isn't your default color scheme on Win2K?

        Believe nothing, no matter where you read it, or who said it - even if I have said it - unless it agrees with your own reason and your own common sense. -- Buddha
        Thanks for the color tip... I was able to sucessfully use it on an old system with a crappy monitor, and people said 'howdya do that?!' :)

Re: The Matrix Reloaded: JAPH
by blackstarr (Friar) on Sep 02, 2003 at 06:28 UTC
    Unlike AnonyMonk, I actually like this.

    Worked perfectly on my Win2K box with Activestate 5.8.0!

    Wonder if anyone could figure out a way for the text to descend the screen, as with the "real" Matrix? Is there a technique someone could point me to, or is it only possible in a graphical client?

    So Long

      A possibility is redrawing the whole screen at each frame. For instance (only tested on linux):

      #!/usr/bin/perl -w # Array containing all lines my @screen = ( ' 'x70 . "\n" ) x 20; # Array of possible (equiprobable) characters my @char = split //, ' *|'; while(1) { print join '', @screen; # Drop last line pop @screen; # Put a new line on top unshift @screen, join ( '', map { $char[ rand(@char) ] } (1..70) ) + . "\n"; # Sleep for 0.1 seconds select(undef, undef, undef, 0.1); }

      Update: The value 20 in the @screen initialization should be at least the terminal height minus 1 (due to the last line being empty). If it's less, then the upper portion of each frame is filled by the last lines of the previous one.



      The stupider the astronaut, the easier it is to win the trip to Vega - A. Tucket

        So, incorporating abell and cfreak's suggestions, you get:

        #!/usr/bin/perl -w @screen = ( ' 'x70 . "\n" ) x 20; $gen_line = sub { my $qw; for(1..70){ if( !$q[$_] && rand > .993 ){ $q[$_] = q$.$ x 5 . q$ $ x 1 . ${ [ qw$tsuJ rehtona lreP rekcaH$ ] }[$qq++] . q$ $ x 1 . q$.$ x 5; $qq = $qq > 3 ? 0: $qq; } if( $q[$_] ){ ( $qx, $q[$_] ) = split//, $q[$_],2; $qw .= $qx; }else{ $qw .= q$ $; } } "\33[0;32m$qw\33[0m"; }; while(1) { print join '', @screen; # Drop last line pop @screen; # Put a new line on top unshift @screen, $gen_line->() . "\n"; # Sleep for 0.1 seconds select(undef, undef, undef, 0.1); }

        Cool, monks! =]

        "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
        Seems to work nicely under ActiveState Perl 5.8.0 on Windows 2000.

        "Ex libris un peut de tout"
Re: The Matrix Reloaded: JAPH
by u914 (Pilgrim) on Sep 01, 2003 at 23:38 UTC
    works peachy with ActiveState 5.8 over WinXP...

    cheers! ;-)

Re: The Matrix Reloaded: JAPH
by mildside (Friar) on Sep 02, 2003 at 05:35 UTC
    I liked it - worked well under Cygwin.


Re: The Matrix Reloaded: JAPH
by zakzebrowski (Curate) on Sep 02, 2003 at 11:23 UTC
    Dude, I was having a crappy day till I read the node and said, hmm. what is all the hubbub about? I must say this is super sweet obfuscation... :) Cheers.

Re: The Matrix Reloaded: JAPH
by nimdokk (Vicar) on Sep 02, 2003 at 12:01 UTC
    Well, that brightened up the start of a potentially crappy day, thanks :-)

    "Ex libris un peut de tout"
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://288199]
Approved by Albannach
Front-paged by jeffa
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2022-12-08 18:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found