Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

ASCII autostereograms

by mstone (Deacon)
on May 06, 2005 at 02:38 UTC ( [id://454579]=CUFP: print w/replies, xml ) Need Help??

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 + + + +

Replies are listed 'Best First'.
Re: ASCII autostereograms
by shemp (Deacon) on May 12, 2005 at 23:15 UTC
    That is really cool! I remember in high school (1991) trying to hand draw stereograms with limited success. I havent fully examined your code, but great idea!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://454579]
Approved by ghenry
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-19 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found