Random ASCII Stereograms

Authors

Publication

Pub Details

Date

Pages

See all articles from QL Hacker's Journal 11

In QHJ #9, Herb Schaaf wrote a program that created Random Dot Stereograms based on a Mathmatica program published in a Mathmatica magazine. A number of RDS’s have been posted to alt.3d in postscript form. Herb and I have ruined our eyes looking at these things. All of the posted RDS’s have a high dot resolution.

Recently, David Coleman posted a different approach to these stereograms called Random ASCII Stereograms (RAS). His program takes an input file that describes the object to show in 3D, and produces an ASCII pattern, that when viewed correctly, shows the object in 3D.

The stereograms are not as complicated as the RDS’s. They only show two levels of 3D, seen as a flat object above a flat surface. The RAS’s are not as interesting as RDS’s but are easily implemented on systems that may not display graphics, easy to port, and simpler to understand than RDS’s.

Upon showing a associate at work, who has a big background in computer security, we wondered if text messages can be embedded into RDS’s and “invisible” to the average person. With RAS’s, this can easily be done. The input file can be a simple representation of characters and then easily e-mailed to others in “private”. Granted, not very private, but private unless you know the trick.

The only changes I have made to Dave’s program are:

  1. Use the proper Rand function for C68.
  2. Send output to a file (flp1_ras_out) instead of stdout.
/*
ras.c A simple random ascii stereogram generator
08/24/92 David Coleman, coleman@netmail.austin.ibm.com
10/05/92 Ported by QL by Tim Swenson
added code to send output to flp1_ras_out
instead of stdout.
tswenson@se3c763a.pl.osd.mil
*/
#include <stdio_h>
#include <stdlib_h>
#include <math_h>

main(argc,argv)
int argc;
char *argv[];
{

int c,d,i,j,k,row,col,flag,done;
char rstr[17];
char line[24][80];
FILE *fp, *fd2;

flag = done = 0;
if (2!=argc) {
fprintf(stderr,"usage: %s datafile\n",argv[0]);
exit(1);
}

srand(getpid());

for (i=0;i<20;i++) {
for (j=1;j<16;j++) {
done=0;
while(0==done) {
c = (43+rnd(79));
flag = 0;
for (k=1;k<j;k++) {
if(rstr[k-1]==c) flag=1;
}
if (0==flag) done=1;
}
rstr[j-1]=c;
}
rstr[16]= '\0';
sprintf(line[i],"%s%s%s%s%s",rstr,rstr,rstr,rstr,rstr);
}

fp=fopen(argv[1],"r");
col = row = 0;
while(!(feof(fp))) {
c=fgetc(fp);
if ('\n'==c) {
col = 0;
++row;
}
else {
++col;
if (' '!=c) {
line[row][col]=line[row][col+1];
d = (43+rnd(79));
line[row][col+1] = d;
if((col+16)<80) {
line[row][col+15]=line[row][col+16];
line[row][col+16] = d;
}
if((col+31)<80) {
line[row][col+30]=line[row][col+31];
line[row][col+31] = d;
}
if((col+46)<80) {
line[row][col+45]=line[row][col+46];
line[row][col+46] = d;
}
}
}
}
fclose(fp);
for(i=0;i<20;i++) {
for(j=60;j<75;j++) {
if((' '==line[i][j])||(0==line[i][j])) line[i][j]=
line[i][j-15];
}
line[i][75]=0;
}

fd2 = fopen("flp1_ras_out","w");
fprintf(fd2," (32 spaces) O O\n");
for(i=0;i<20;i++) fprintf(fd2,"%s\n",line[i]);
fclose(fd2);
}

int rnd(num)
{
rand();
return (rand() % num);
}

Random ASCII Stereogram Sample Data File: ras_dat

                          #
##
###
#### #######
##### #######
###### #######
####### #######
########
#########
##########
###########
############
#############
##############

Products

 

Downloadable Media

 

Image Gallery

Scroll to Top