I was trying to explain random-dot stereograms to a friend today, and wrote a little script that generates simple ASCII stereograms as a stepping stone along the way. The code isn't terribly exciting, but the whole 'scalars floating in space' thing is kinda pretty:

+ $step+ $step + $step + $Co$W $S $Co$W $S $Co$W $S $Co$W $z $L $z $L $z $L $z $W $L $W $L $W $L $W + + + +

The code (and a larger tableau) is below the fold. There's also a node about generating random-string stereograms from a height field here.

#!/usr/bin/perl use Strict; my $W = 18; # column width my $H = 31; # column height my $C = 3; # number of column repeats my $L = 5; # number of layers my $S = 4; # step between items my @E = (); seek (DATA,0,0); for (<DATA>) { push @E, /(\$\w+)/g; # harvest scalar names from the source } my @grid = (' 'x($W * $C))x$H; # build the basic array for my $i (0..$C) { # add the registration marks for my $j (0..($#grid / 5)) { substr ($grid[ $j*5 ], $i*$W, 1) = '+'; } } for my $layer (1..$L) { # add items from back to front my $step = $W - $layer; # set the offset for this layer for (my $z=0 ; $z < $H ; $z+=2+rand $S) { my $x = rand ($W); my $y = rand ($H); # choose a random position/string my $e = $E[ rand @E ]; for (my $pos=$x ; $pos<length($grid[$y]) ; $pos+=$step) { substr ($grid[$y], $pos, length $e) = $e; } } } print join ("\n", @grid), "\n"; __DATA__ ----- END OF FILE ----- +$W $W + $W + $W + $j $j $j $j $j $j $grid $$eid $erid $egrid + + + + $pos $posC $pos $C $pos $pos $pos $pos $H $W $W $W$H $W$W $W $H$$W $W $$W + + + + $layer $elayer $e $layer $e $lay$e $x $j $x $j $x $j $x $pos $pos $pos $pos + $pos+ $pos + $pos $pos $grid $C $grid $C $gridpos $C $grid $pos $i $i $i $i + $step+ $step + $step + $Co$W $S $Co$W $S $Co$W $S $Co$W $z $L $z $L $z $L $z $W $L $W $L $W $L $W + + + + $z $H$H $z$H $H $H $H $H$z $j$step $pos $j $ste$pos$H $j $s$pos $H $j $j $j $j $W $pos $W $pos $W $p$W + + + +

In reply to ASCII autostereograms by mstone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.