home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / mktrans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-26  |  2.6 KB  |  88 lines

  1. /****************************************\
  2. *                                        *
  3. *            mktrans.c                *
  4. *                         *
  5. *      cellular automaton simulator      *
  6. *                                        *
  7. *      generates transition files       *
  8. *                                        *
  9. *                                        *
  10. \****************************************/
  11.  
  12.  
  13. /* August 29, 1988 */
  14.  
  15. #include <stdio.h>
  16.  
  17. #define UNDEF    '\377'            /* undefined character         */
  18. #define ASCZ    '0'            /* ASCII zero                  */
  19. #define TRUE     1
  20. #define FALSE    0
  21. #define add_index(k)    index <<= L;  index |= k
  22.  
  23. /***********************************************************************\
  24. *                                                                       *
  25. * To adapt this file for generating your own transition function:       *
  26. *   1.    Change the constants below as appropriate.                      *
  27. *   2.    Insert the desired function inside the for loops.               *
  28. *   3.    Depending on which neighborhood you are using, change the       *
  29. *     order of for-loops and indices as follows (tl = top-left,       *
  30. *     ll = left-of-left, etc.):                                       *
  31. *         VonN:    l, c, r, t, b                                   *
  32. *         Moore:    tl, l, bl, t, c, b, tr, r, br                   *
  33. *         linear,    r=1:    l, c, r                                 *
  34. *             r=2:    ll, l, c, r, rr                         *
  35. *             r=3:    lll, ll, l, c, r, rr, rrr               *
  36. *                                                                       *
  37. \***********************************************************************/
  38.  
  39. #define    S    8            /* number of states/cell       */
  40. #define    L    3            /* log S                      */
  41. #define    N    5            /* number of neighbors: von N  */
  42. #define TSIZE    32768            /* size of t-table:  S ^ N     */
  43. #define NAME    "temp.v8"        /* output file name            */
  44.  
  45.  
  46.  
  47. main()
  48. {
  49.     int     l, c, r, t, b, next, index;
  50.     char    ta[TSIZE];            /* t-table array       */
  51.     FILE   *fopen(), *fp;
  52.  
  53.  
  54.     /* main code begins */
  55.  
  56.     for (l = 0; l < S; l++)
  57.     for (c = 0; c < S; c++)
  58.         for (r = 0; r < S; r++)
  59.         for (t = 0; t < S; t++)
  60.             for (b = 0; b < S; b++) {
  61.  
  62.             index = 0;
  63.             add_index(l);
  64.             add_index(c);
  65.             add_index(r);
  66.             add_index(t);
  67.             add_index(b);
  68.  
  69.  
  70.             /* l, c, r, t, b = left, center, right, top, bottom */
  71.             /* now define next as a function of these, e.g.     */
  72.  
  73.             next = (c + r + l + t + b) % 8;
  74.  
  75.             /* gives modulo 8 addition.                         */
  76.             
  77.  
  78.             ta[index] = next;
  79.  
  80.             }
  81.  
  82.  
  83.     fp = fopen(NAME, "w");
  84.     fwrite(ta, sizeof(*ta), TSIZE, fp);
  85.     fclose(fp);
  86.  
  87. } /* main */
  88.