home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-2 / WAVY.C < prev    next >
Text File  |  2000-06-30  |  2KB  |  70 lines

  1. /*
  2.     Wavy Lines for the H19/Z19/H89/Z89
  3.     Written by Leor Zolman, 11/81
  4.  
  5.     This program is configured for the H19 terminal, but may be used
  6.     on ANY cursor-addressable terminal by:
  7.  
  8.         a) modifying the first four #define lines to suit your
  9.            particular terminal, and
  10.         b) modifying the cursor addressing sequence (commented)
  11.            in the program to work for your terminal.
  12.  
  13.     For best effect, compile with:
  14.       A>cc1 wavy.c -e2000 -o <cr>
  15. */
  16.  
  17. /* The following four #define statements need customizing for your terminal: */
  18.  
  19. #define INIT    "\33E\33F\33x5"    /* clear screen, enter graphics mode,    */
  20.                 /* and turn off the cursor        */
  21. #define UNINIT    "\33E\33G\33y5"    /* clear screen, exit graphics mode,    */
  22.                 /* and turn cursor back on        */
  23.  
  24. #define SLASH 'x'        /* these are special characters in H19    */
  25. #define BACKSLASH 'y'        /* graphics mode. If you don't have an  */
  26.                 /* H19, make these simply '/' and '\\'    */
  27.  
  28.  
  29. #define MAXL 200        /* maximum number of lines at one time */
  30.  
  31. int direc[MAXL];
  32. char column[MAXL];
  33. char i;
  34. char nlines;
  35.  
  36. main()
  37. {
  38. top:    puts(UNINIT);
  39.     srand1("How many wavy lines (1-200, q to quit) ? ");
  40.     if (!scanf("%d",&nlines) || nlines < 1 || nlines > MAXL) exit();
  41.     puts(INIT);
  42.  
  43.     for (i=0; i<nlines; i++)    /* initialize lines */
  44.     {
  45.         column[i] = 40;        /* start out at center */
  46.         direc[i] = rand() % 2 * 2 - 1;
  47.     }
  48.  
  49.     while (1)
  50.     {
  51.        putch('\n');
  52.        if (kbhit() && getchar()) goto top;    /* if key hit, stop    */
  53.  
  54.        for (i = 0; i < nlines; i++)
  55.        {    
  56.         putch('\33');        /* position cursor at row 23,     */
  57.         putch('Y');        /*               column i    */
  58.         putch(' '+23);        /*   MODIFY THIS SECTION FOR    */
  59.         putch(' '+column[i]);    /*     NON-H19 TERMINALS!    */
  60.  
  61.         putch ((direc[i] == -1) ? SLASH : BACKSLASH);
  62.  
  63.         if (rand() % (40 - (column[i]-39) * direc[i]))
  64.             column[i] += direc[i];    /* keep same direction    */
  65.         else
  66.             direc[i] = -direc[i];    /* change direction    */
  67.        }
  68.     }
  69. }
  70.