[comp.sources.atari.st] v02i087: truchet -- Display random Truchet tilings on mono screens

koreth@panarthea.ebay.sun.com (Steven Grimm) (10/10/89)

Submitted-by: BD05@DKAUNI2.Bitnet (Roland Waldi)
Posting-number: Volume 2, Issue 87
Archive-name: truchet

Here is the source to the truchet tiling demo, which I submitted to
the binaries group earlier.

/*-------------------------------------------------------------*
 *                                                             *
 * TRUCHET2.C: main()                                          *
 * display random Truchet tiles on a monochrome screen         *
 *                                                             *
 * compiler used: LASER C (Atari ST)                           *
 *                                                             *
 * The comments may be used to get a better view of the        *
 * program structure: type 'EXCLUDE /**' for the top level     *
 * structure, 'EXCLUDE /***' to reveal the next level etc.     *
 * where 'EXCLUDE' should be replaced by the appropriate       *
 * command of your favourite editor.                           *
 *                                                             *
 *-----Version 1.00-----(C) 1989 Roland Waldi------------------*/
                                              /*  */
#include <osbind.h>                           /*  */
                                              /*  globals */
int  *screen[2];                              /** globals */
int   tile[2][16] = {128,128,192,64,          /** globals ... */
                    96,48,28,-4089,           /*** globals */
                    7168,1536,768,256,        /*** globals */
                    384,128,128,128,          /*** globals */
                                              /*** globals */
                    128,128,384,256,          /*** globals */
                    768,1536,7168,-4089,      /*** globals */
                    28,48,96,64,              /*** globals */
                    192,128,128,128};         /*** globals */
/*****  ........X.......   128         ........X.......   128 */
/*****  ........X.......   128         ........X.......   128 */
/*****  ........XX......   192         .......XX.......   384 */
/*****  .........X......    64         ...... X........   256 */
/*****  .........XX.....    96         ......XX........   768 */
/*****  ..........XX ...    48         .....XX.........  1536 */
/*****  ...........XXX..    28         ...XXX..........  7168 */
/*****  XXXX.........XXX -4089         XXXX.........XXX -4089 */
/*****  ...XXX..........  7168         ...........XXX..    28 */
/*****  .....XX.........  1536         ..........XX....    48 */
/*****  ......XX........   768         .........XX.....    96 */
/*****  .......X........   256         .........X......    64 */
/*****  .......XX.......   384         ........XX......   192 */
/*****  ........X.......   128         ........X.......   128 */
/*****  ........X.......   128         ........X.......   128 */
/*****  ........X.......   128         ........X.......   128 */
                                              /*** */
long RINT = 7716383l;                         /** globals for Rn */
long RMULT = 331804469l;                      /** globals for Rn */
                                              /** */
main()                                        /*  main */
{                                             /*  main */
  int actual;                                 /** declarations */
  register int i, n;                          /** declarations */
  register int  *c;                           /** declarations */
  long temp;                                  /** declarations */
                                              /** */
  if (Getrez() != 2)  Pterm(1);               /** check resolution */
  actual = 1;                                 /**  initialize ... */
  screen[0] = (int  *)Physbase();             /*** initialize */
  temp = Malloc(32256l);                      /*** initialize */
  if (!temp)       Pterm(2);                  /*** initialize */
  screen[1] = (int  *)((temp+256)&0xFFFF00l); /*** initialize */
  a_hidemouse();                              /*** initialize */
  RINT += Tgettime();                         /*** initialize */
                                              /** */
  for (n=0; n<1000; n++)                      /**  init loop */
  {                                           /**  init loop */
    copytile(0,n,actual);                     /*** init loop */
  }                                           /**  init loop */
  Setscreen(-1l,screen[actual],-1);           /**  initialize ... */
  Vsync();                                    /*** initialize */
                                              /** */
  while (!Cconis())                           /**  main loop */
  {                                           /**  main loop */
    actual = !actual;                         /*** main loop */
    fwcopy(screen[actual],screen[!actual],    /*** main loop */
           32000l);                           /*** main loop */
    n = Rn(1000);                             /*** main loop */
    c = screen[actual]                        /*** main loop */
          + (n/40) * 640 + (n%40) + 320;      /*** main loop */
    i = (*c)>>12;                             /*** flip tile */
    copytile(i,n,actual);                     /*** flip tile */
    Setscreen(-1l,screen[actual],-1);         /*** main loop */
    Vsync();                                  /*** main loop */
  }                                           /**  main loop */
                                              /** */
  Setscreen(-1l,screen[0],-1);                /**  terminate ... */
  Vsync();                                    /*** terminate */
  a_showmouse();                              /*** terminate */
  Mfree(temp);                                /*** terminate */
  Pterm(0);                                   /*** terminate */
}                                             /*  end main */
                                              /*  */
copytile(i,n,actual)                          /*  copytile */
register int i, actual; int n;                /*  copytile */
{                                             /*  copytile */
  register int j;                             /** declarations */
  register int *start;                        /** declarations */
                                              /** */
  start = screen[actual]                      /**  get address ... */
          + (n/40) * 640 + (n%40);            /*** get address */
  for (j=0; j<16; j++)                        /**  copy loop */
  {                                           /**  copy loop */
    *(start + j*40) = tile[i][j];             /*** copy loop */
  }                                           /**  copy loop */
                                              /** */
  return;                                     /** copytile */
}                                             /*  end copytile */
                                              /*  */
int Rn(n) int n;                              /*  Rn */
/* Random number generator, return pseudo random number in [0...n-1] */
{                                             /*  Rn */
  RINT = (RINT * RMULT) - 1;                  /** Rn */
  return (int)( (((RINT & 0x7FFFFFFFl) >> 16) /** Rn */
                  * n) /  0x8000l );          /** Rn */
}                                             /*  end Rn */