Acme-AsciiArtinator
view release on metacpan or search on metacpan
lib/Acme/AsciiArtinator.pm view on Meta::CPAN
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
compile or to behave differently.
The ASCII Artinator tokenizes the code and
does its best to identify
=over 4
=item 1. Character strings that must not be divided
These include alphanumeric literals, quoted strings,
and most regular expressions.
=item 2. Places in the code where it is OK to insert padding.
=item 3. Places in the ASCII artwork where there are multiple
consecutive darkspace characters
=back
The next step is to try to align the tokens from the code
with enough contiguous blocks of darkspace in the art. When
a token is misaligned, we attempt to align it by inserting
some padding at some point in the code before that token.
There are currently two ways that we pad the code. Each
time there is a need to pad the code, we randomly choose
a padding method and randomly choose an eligible position
for padding.
=over 4
=item 1. Inserting semi-colons at the beginning or end of a statement
In general, we can put as many semi-colons as we like at the beginning
or end of statements. The following lines of code should all do the
same thing:
$a=$b+$c;$d=4
$a=$b+$c;;;;;;$d=4;;;;;;
;;;;;;;;;$a=$b+$c;;;;;;;;$d=4;
=item 2. Putting braces around a variable name.
In general, we can replace C<$name> with C<${name}> and the code
will run the same.
=back
There are several other interesting ways to pad code (putting parentheses
around expressions, adding and or-ing zeros to expressions, using quoted
strings in a void context) that may be put to use in future versions
of this module.
When all tokens from the code are successfully aligned with the
blocks of darkspace from the artwork, we can paste the code on top
of the art and write the output file.
Sometimes we insert too many characters without successfully
aligning the tokens and darkspace blocks (and actually in the
spider example, this happens about 90% of the time). If this
happens, we will start over and retry up to 100 times.
=head1 BEST PRACTICES
lib/Acme/AsciiArtinator.pm view on Meta::CPAN
=item debug => 0 | 1
Causes the ASCII Artinator to display verbose messages
about what it is trying to do while it is doing what it
is trying to do.
=item test_argv1 => [ @args ], test_argv2 => [ @args ] , test_argv3 => ...
Executes the original and the artinated code and compares the output
to make sure that the artination process did not change the
behavior of the code. A separate test will be conducted for
every C<test_argvE<lt>NNNE<gt>> parameter passed to the
C<asciiartinate> method. The arguments associated with each
parameter will be passed to the code as command-line arguments.
=item test_input1 => [ @data ], test_input2 => [ @data ], test_input3 => ...
Executes the original and the artinated code and compares the output
to make sure that the artination process did not change the
behavior of the code. A separate test will be conducted for
every C<test_inputE<lt>NNNE<gt>> parameter passed to the
C<asciiartinate> method. The data associated with each
parameter will be passed to the standard input of the code.
=back
=head1 TODO
Lots of future enhancements are possible:
=over 4
=item * Use new ways of padding code
=back
=over 4
=item * Take big blocks of filler and fill them with something else. Random quoted strings.
=back
=over 4
=item * Try to align whitespace in the code with whitespace in the art.
=back
=over 4
=item * Have a concept of "grayspace" in the artwork. These are positions where
we can put either whitespace or a character from the code, whichever makes it
easier to align the code.
=back
=over 4
=item * Optionally implement some "best practices" automatically to make the code
more flexible without changing its behavior.
=back
=head1 BUGS
Probably lots.
=head1 SEE ALSO
If you liked this module, you might also get a kick out of L<Acme::EyeDrops>.
=head1 AUTHOR
Marty O'Brien, E<lt>mob@cpan.orgE<gt>
=head1 LICENSE AND COPYRIGHT
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.
=cut
( run in 3.363 seconds using v1.01-cache-2.11-cpan-54e63673c56 )