Acme-AsciiArtinator
view release on metacpan or search on metacpan
lib/Acme/AsciiArtinator.pm view on Meta::CPAN
=head1 VERSION
0.04
=head1 SYNOPSIS
use Acme::AsciiArtinator;
asciiartinate( { art_file => "ascii.file",
code_file => "code.pl",
output => "output.pl" } );
=head1 DESCRIPTION
Embeds Perl code (or at least gives it a good
college try) into a piece of ASCII artwork by
replacing the non-whitespace
(we'll refer to C<non-whitespace> a lot in this
document, so let's just call it
C<darkspace> for convenience) characters of an
ASCII file with the characters of a Perl script.
If necessary, the code is modified (padded) so
that blocks of contiguous characters (keywords,
quoted strings, alphanumeric literals, etc.)
in the code are aligned with at least the
minimum number of contiguous darkspace
characters in the artwork.
=head1 EXAMPLE
Suppose we have a file called C<spider.pl> with
the following code:
&I();$N=<>;@o=(map{$z=${U}x($x=1+$N-$_);
' 'x$x.($".$F)x$_.($B.$z.$P.$z.$F).($B.$")x$_.$/}
0..$N);@o=(@o,($U.$F)x++$N.($"x3).($B.$U)x$N.$/);
print@o;
sub I{($B,$F,$P,$U)=qw(\\ / | _);}
while($_=pop@o){y'/\\'\/';@o||y#_# #;$t++||y#_ # _#;print}
What this code does is read one value from standard input
and draws a spider web of the given size:
$ echo 5 | perl spiders.pl
\______|______/
/\_____|_____/\
/ /\____|____/\ \
/ / /\___|___/\ \ \
/ / / /\__|__/\ \ \ \
/ / / / /\_|_/\ \ \ \ \
_/_/_/_/_/_/ \_\_\_\_\_\_
\ \ \ \ \ \___/ / / / / /
\ \ \ \ \/_|_\/ / / / /
\ \ \ \/__|__\/ / / /
\ \ \/___|___\/ / /
\ \/____|____\/ /
\/_____|_____\/
/ | \
Suppose we also have a file called C<spider.ascii>
that looks like:
; ,
,; '.
;: :;
:: ::
:: ::
': :
:. :
;' :: :: '
.' '; ;' '.
:: :; ;: ::
; :;. ,;: ::
:; :;: ,;" ::
::. ':; ..,.; ;:' ,.;:
"'"... '::,::::: ;: .;.;""'
'"""....;:::::;,;.;"""
.:::.....'"':::::::'",...;::::;.
;:'.'""'"";.,;:::::;.'"""""". ':;
::' ;::;:::;::.. :;
::. ,;:::::::::::;:.. ::
;' ,;;:;::::::::::::::;";.. ':.
:: ;:" ::::::"__':::::: ": ::
:. :: ::::::;__::::::: :: .;
; :: :::::::__::::::: : ;
' :: ::::::....:::::' ,: '
' :: :::::::::::::" ::
:: ':::::::::"' ::
': """""""' ::
:: ;:
':; ;:"
'; ,;'
"' '"
And B<now> suppose that we think it would be
pretty cool if the code that draws spider
webs on the screen actually looked like a
spider. Well, this is a job for the Acme::AsciiArtinator.
Let's code up a quick script that just says:
use Acme::AsciiArtinator;
asciiartinate( art_file => "spiders.ascii",
code_file => "spiders.pl",
output => "spider-art.pl" );
and run it.
If this works (and it might not, for a variety of
reasons), we will get a new file called C<spider-art.pl>
that looks something like:
& I
() ;$
N= <>
;; ;;
;; ;;
;; ;
;; ;
;; ;; ;; ;
;; ;; ;; ;;
;; ;; ;@ o=
( map {$z =$
{U }x( $x= 1+
$N- $_) ;' 'x $x. ($".
$F)x$_ .($B.$z.$ P. $z.$F).
($B.$")x$_.$/}0..$N);@
o=(@o,($U.$F)x++$N.($"x3).($B.$U
)x$N.$/);;;;print@o;;;sub I{( $B,
$F, $P,$U)=qw(\\ /
| _);;}while($_=pop @o
){ y'/\\'\/';;;@o||y#_# #;; ;;;
;$ t++ ||y#_ # _#;print }# ##
## ## ################ ## ##
# ## ################ # #
# ## ################ ## #
# ## ############## ##
## ############ ##
## ######## ##
## ##
### ###
## ###
## ##
Hey, that was pretty cool! Let's see if it works.
$ echo 6 | perl spider-art.pl
\_______|_______/
/\______|______/\
/ /\_____|_____/\ \
/ / /\____|____/\ \ \
/ / / /\___|___/\ \ \ \
/ / / / /\__|__/\ \ \ \ \
/ / / / / /\_|_/\ \ \ \ \ \
_/_/_/_/_/_/_/ \_\_\_\_\_\_\_
\ \ \ \ \ \ \___/ / / / / / /
\ \ \ \ \ \/_|_\/ / / / / /
\ \ \ \ \/__|__\/ / / / /
\ \ \ \/___|___\/ / / /
\ \ \/____|____\/ / /
\ \/_____|_____\/ /
\/______|______\/
/ | \
=head1 UNDER THE HOOD
To fill in the shape of the spider, we inserted whitespace,
semi-colons, sharps, and maybe the occasional C<{> C<}> pair
into the original code. Certain blocks of text, like
C<print>, C<while>, and C<y#_ # _#> are kept intact since
splitting them would cause the program to either fail to
( run in 1.799 second using v1.01-cache-2.11-cpan-d80b1682f3f )