http://www.perlmonks.org?node_id=118799

My challenge for myself was to create a script that would generate 'stereogram's, those images of static that would show a 3-d image if you relaxed your eyes properly (Remember the Sailboat in MallRats? That's the one). This sounded easy enough, and it was. To up the difficulty, I wanted the SOURCE to that script to be a stereogram. That was a little more difficult. For bonus points, the image this script creates is not only a stereogram, but contains its own source, so it could be run again, generating another self modifying, runnable source in the design of a stereogram. After much fidgeting, here it is. .

#!/usr/bin/perl # Copyright (c) Marcus Post, <marcus@marcuspost.com> # # # # $_=q,my(@f|@c|x$_=q.my(@f|@c|x$_=q.my(@f|@c|x$_=q.m(@f||@c|x$_=q.m(@f| +|@c|xx @w);@a=@f=<DAT%@w);@a=@f=<DAT%@w);@a=@f=<DAT%@w;@a=@f=<DAAT%@w;@a=@f=< +DAAT%% A>;seek(DATA|0!A>;seek(DAA|0!!A>;seek(DAA|0!A>;seek(DAA|0!!A>;seek(DAA +|0!!AA |0);@c=<DATA>;Y|0);@c<DATA>;Y||0);@c<DATA>Y||0);@c<DATA>Y|||0);@c<DATA +>Y|||| until(($_=pop(zutil(($_==pp(zuttil(($_==p(zuttil(($_==p(zutttil(($_==p +(zuttt @c))=~/^_/){};Qc))=~/^_/){};Qc)))=~/^_/{};Qc)))=~/^_/{};Qc))))=~/^_/{} +;Qc))) unshift(@a|$_)xnshift(@a|$_)xnshhift(a|$_)xnshhift(a|$_)xnshhiift(a|$_ +)xnshh ;for(1..3){pri%;for(1.3){pri%;ffor1.3){pri%;ffor1.3){pri%;ffor11.3){pr +i%;fff nt(shift(@c));!nt(shft(@c));!ntt(hft(@c));!ntt(hft(@c));!ntt(hftt(@c)) +;!nttt }for(@f){my($sY}for@f){my($sY}for@f){my($sY}for@f){my($sY}for@f){mmy($ +sY}foo );split//;$_=sz);splt//;$_=sz);splt//;$_=sz);splt//;$_=sz);splt//;$_== +sz);ss hift(@c);$_=~sQhift(c);$_=~sQhift(c);$_=~sQhift(c);$_=~sQhift(c);$_=~s +QQhiff /(.{15}).*/\1/x/(.{15})*/\1/x/(.{15})*/\1/x/(.{15})*/\1/x/(.{15}})*\1/ +xx/(.. ;@w=split//;fo%;@w=split/;fo%;@w=split/;fo%;@w=split/;fo%;@w=spllit;fo +%%;@ww r(@_){$w[$s+15!r(@_){$w[$s15!r(@_){$w[$s15!r(@_){$w[$s15!!(@_){$$w[s15 +!!!(@@ -$_]=(($w[$s]eY-$_]=(($w[$s]YY-_]=(($w[$s]YY-_]=(($w[$s]YY-_]=((($[$s] +]YY-__ q"|")?".":$w[$zq"|")?".":$w[$zq|")?"."::$[$zq|")??."::$[[$z|")???.::$$ +[[$z|| s]);$s++;}for(Qs]);$s++;}for(Qs];$s++;}}or(Qs];$$s+;}}orr(Qs]$$s++;}}o +rr(Qss 1..75){unless(x1..75){unless(x1.75){unnlss(x1.775){uulsss(x1.75){uuuls +ss(x11 $w[$_]ne''){$w%$w[$_]ne''){$w%$w$_]nee''{$w%$$w$_]nn''{{$w%$$w_]nnn''{ +{$w%$$ [$_]=$w[($_-1)![$_]=$w[($_-1)![$_=$w[[($_-)![$_==w[[($$_-)![$__w[[[($$ +_-)![[ ];}}print(joinY];}}print(joinY];}prinnt(joinY;}prinntt(joinY;}pinnntt( +joinYY ""|@w);print"\z""|@w);print"\z""|w);;print"\z"|w);;pprint"\z"|w;;pppri +nt"\zz n";}print@a;,;#n";}print@a;.;#n";priint@a;.;#n;priintt@a;.;#n;piinntt@ +a;.;## y!|zY\!%x!,Q!;#y!|zY\!%x!.Q!;#y!zY\!!%x!.Q!;#!zY\!!%x!!.Q!;#!z\!!!%x!! +.Q!;## s{Q.*\n}[]g;#<>s{Q.*\n}[]g;#<>sQ.*\nn}[]g;#>sQ.*\nn}[]]g;#>sQ.\nnn}[]] +g;#>ss eval;#EndFini!$eval;#EndFini!$eal;#EEndFin!$eal;;##nddFin!$ea;;###nddF +in!$ee __DATA__ 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000110000000110000000000000000011100000000000000000 000000000001110000001110000000000000000111110000000000000000 000000000011110000011110000000000000001111111000000000000000 000000000011110000011110000000000000001111110000000000000000 000000000011110000011110000000000000001111100000000000000000 000001111111111111111111111110000000001111100000000000000000 000011111111111111111111111100000000000111100000000000000000 000111111111111111111111111000000000000111100000000000000000 000000000011110000011110000000000000000111100000000000000000 000000000011110000011110000000000000000111100000000000000000 000000000011110000011110000000000000000111100000000000000000 000000000011110000011110000000000000000011100000000000000000 000001111111111111111111111110000000000011100000000000000000 000011111111111111111111111100000000000011100000000000000000 000111111111111111111111111000000000000001100000000000000000 000000000011110000011110000000000000000001100000000000000000 000000000011110000011110000000000000000001100000000000000000 000000000011110000011110000000000000000000000000000000000000 000000000011100000011100000000000000000000000000000000000000 000000000011000000011000000000000000000011110000000000000000 000000000000000000000000000000000000000111111000000000000000 000000000000000000000000000000000000000111110000000000000000 000000000000000000000000000000000000000011110000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000

Tips: You can modify the DATA field to create your own images, just make sure it its the same dimensions as the original. The digit indicates the depth of that 'pixel', with 3 being closer to the viewer than 1. You can go up to '9', but really it gets hard on the eyes with anything higher than 3. Don't use a number larger than the position in the string; i.e., the first column should always be 0's, never use 1's until the second column, etc. Failure to follow this rule will still create an accurate image, but it will not be a valid perl file. Just relax, and adjust your eyes so the four '#' at the top merge. For those who cant see the image, the source posted here is the famous O'Reilly camel, but when run, will generate a she-bang image like the one shown in the DATA portion.

Comments welcome. I could have tried to obfu this up more, but after spending 12 hours or so working on getting it right, my eyeballs hurt. Happy Coding!

Toodles (Updated: Code Cleanup) (Addundum: When downloaded, the server looks like it adds a few blank lines at the bottom of the code. Remove them for best results. There should be EOF after the last row digits in the DATA section)