Subject: Re: stereo programs in C

From: [email-masked] (Greg Alt)
Date: 7 Oct 92 17:03:18 GMT

In article <[email-masked]>, [email-masked] (WILLIAMSON, JOHN EDWARD) writes:
>Work has forced me to dust off my C compiler again.  I saw at least
>two quasi-random dot stereogram programs using ascii character sets
>in this newsgroup in the last few months.  
>
>Can someone email or repost them for me so I can have some fun with
>my C compiler?

/* stereoascii.c  by Greg Alt ([email-masked]) */
#include <math.h>
#include <stdio.h>
main()
{
   char mask[81],out[81],shift,i;

   /* print line at top to use as a guide for viewing */
   printf("%31sX%15sX\n","","");

   /* read in each mask until end of input */
   while(gets(mask)!=NULL)
   {
      /* wipe unused part of mask */
      for(i=1;i<80;i++)
        if(mask[i-1]==0) mask[i]=0;

      /* create output string one character at a time */
      for(out[80]=shift=i=0;i<80;i++)
      {
         /* character is random if it comes right after a shifted portion */
         /*   or if it is in the first 16 characters */ 
         if((shift && mask[i-16]!='#') || i<16)
         {
            shift=0;
            /* random character between 'A' and 'z' */
            do 
              out[i]=random()%('z'-'A')+'A';
            while(out[i]==out[i-1] || out[i]==out[i-15]) ;
         }
         else 
         {
            /* if the mask character is a '#' then shift */
            shift=(mask[i-16]=='#')?1:0;
            /* copy the character from previous column, shifting if necessary */
            out[i]=out[i-16+shift];
         }
      }
      /* print line */
      puts(out);
   }
}