Hmmm... a japh-like idea I had when I was looking at a page-layout engine design at work. I didn't have time to obfuscate it really hard, and will take suggestions.
There's just a bit of mild obfuscation, a couple of odd syntax tricks, a few little-used Perl features. This is a straightforward one to take apart, and it's 5.6 clean. Enjoy!
#!/usr/bin/perl -w
$s=2;($p)=@m=(0,0,1,0);$/=\1;
sub t{@m[2,3]=(0,0);for$y(split//,$_[0]){for(2,3) {
$m[$_]+={n=>[-1,0],s=>[1,0],e=>[0,1],w=>[0,-1]}->{$y}->[$_-2];}}}
$SIG{__WARN__}=sub{$p=!$p};seek DATA,0,0;
for (qw( 6 se p 2 e 2 ne
2 n 5 p e 2 s
8 p n 6 ne 2 e
1 se 2 s 5 n 2 w 4 e 4
p e 2 s 3 p
n 8 e 4 se 1
s 2 sw 1 w 4 p
se 4 e 3 p n 8
s 4 e 4 n 4 s
7
)) { $_[0]=$_;tr/nsew//?&t:&f}
sub f{for(1..$_[0]*$s) {for(0,1){$m[$_]+=$m[$_+2]}if
($p){while(<DATA>){$t=$_;tr/\n\t //||last;}}$g[$m[0]][$m[1]]=$p?$t:" "
+;}}
for$i(0..20){for(0..60){print $g[$i][$_]||" ";}print"\n";}
__END__
PS: Change the $s=2 to another positive integer to change the scale. The 20 and 60 may also have to be changed if you go large. You
will have to run this from a file.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.