From: coleman@casey.austin.ibm.com
Newsgroups: alt.3d
Subject: Source for random ascii stereogram generator
Date: 24 Aug 92 19:57:41 GMT
Distribution: usa
Organization: IBM, Austin

Sorry if one has already been posted, but here is a quick
random ascii stereogram generator that reads a datafile.
I was concentrating more on function than coding style.
No checking is done on the data file, so for best results,
use only columns 15-60, rows 3-17 and "figures" at least 3 characters
wide and 2 characters tall.
----------------Sample Source-------------------------------------
/*
	sg.c   A simple random ascii stereogram generator
        08/24/92    David Coleman, coleman@netmail.austin.ibm.com
*/
#include <stdio.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;

        flag =  done = 0;
        if (2!=argc)  {
          fprintf(stderr,"usage: %s datafile\n",argv[0]);
	  exit(1);
	}
	srandom(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;
        }

        printf("                               O              O\n");
        for(i=0;i<20;i++) printf("%s\n",line[i]);


}
int rnd(num)
{
	extern long random();
	return (random() % num);
}
----------------Sample Data File----------------------------------


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

----------------Sample Output-------------------------------------
                               O              O
q^C,5@xY<+;gtpGq^C,5@xY<+;gtpGq^C,5@xY<+;gtpGq^C,5@xY<+;gtpGq^C,5@xY<+;gtpG
>jRaT<=85KL:xym>jRaT<=85KL:xym>jRaT<=85KL:xym>jRaT<=85KL:xym>jRaT<=85KL:xym
Bb_>G`lXc=4Dq.HBb_>G`lXc=4D.nHBb_>G`lXc=4D.nHBb_>G`lXc=4D.nHBb_>G`lXc=4D.nH
8dr0]f;/nJ-t+=Y8dr0]f;/nJ-t=YP8dr0]f;/nJ-t=YP8dr0]f;/nJ-t=YP8dr0]f;/nJ-t=YP
>Yu1nCi34pyPsHE>Yu1nCi34pyPHE>]Yu1nCi34pyPHE>]Yu1nCi34pyPHE>]Yu1nCi34pyPHE>
EvJwIZb>aLhB+WGEvJwIZb>aLhBWGEvOJwIZb>aLhWGEvOJw\IZb>aLhWGEvOJw\IZb>aLhWGEv
@RM4jr;sbgYoa]:@RM4jr;sbgYo]:@RM-4jr;sbgY]:@RM-4Njr;sbgY]:@RM-4Njr;sbgY]:@R
b@YF_p/W7Gn?.K[b@YF_p/W7Gn?K[b@YFY_p/W7GnK[b@YFYQ_p/W7GnK[b@YFYQ_p/W7GnK[b@
CY.MJ]yE?:gr06nCY.MJ]yE?:gr6nCY.MJt]yE?:g6nCY.MJ7t]yE?:g6nCY.MJ7t]yE?:g6nCY
_RS<=2hI5C]8JuQ_RS<=2hI5C]8uQ_RS<=2KhI5C]8uQ_RS<=2KhI5C]8uQ_RS<=2KhI5C]8uQ_
x_s/B=dDCy:gX@rx_s/B=dDCy:g@rx_s/B=dDDCy:g@rx_s/B=dDDCy:g@rx_s/B=dDD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