home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_08 / v6n8053a.txt < prev    next >
Text File  |  1989-09-28  |  4KB  |  136 lines

  1. /* sketchpad.c - Interactively draw on the Apple II high resolution display,
  2.  * demonstrating the library hr_apple2.lib.  Print a menu of valid commands
  3.  * which will remain in the text page and can be redisplayed by returning to
  4.  * text mode.  Until the QUIT command is received, execute the command then
  5.  * wait for the next valid command.  The user specifies the color and then
  6.  * uses the cursor control keys to draw in that color.
  7.  */
  8.  
  9. #include <stdio.h,d1>
  10. #include <math.h,d1>
  11. #include <kbctl.h,d1>
  12. #include <hr_apple2.h>
  13.  
  14. main()
  15. {    int x = 0;                    /* column number - initially 0 */
  16.     int y = 0;                    /* row number - initially 0 */
  17.     int clr = HR_BLACK;            /* color  - initially black */
  18.     int sop = HR_PG1BGN;        /* start of page  - initially page 1 */
  19.     int eop = HR_PG1END;        /* end of page - initially page 1 */
  20.     char cmd;                    /* user command */
  21.  
  22.     cmd = ioctl( stdin , KB_CLEAR );        /* clear the screen */
  23.     cmd = ioctl( stdin , KB_ECHO , 0 );        /* disable keyboard echo */
  24.  
  25.     /* Print the 'help' menu */
  26.  
  27.     printf( "DRAW ON THE HIGH RESOLUTION DISPLAY\n" );
  28.     printf( "\nUSE THE CURSOR KEYS TO DRAW AND THE FOLLOWING KEYS:\n" );
  29.     printf( "\nH = DISPLAY THIS HELP MENU\n" );
  30.     printf( "Q = QUIT\n" );
  31.     printf( "C = CLEAR PAGE TO CURRENT COLOR\n" );
  32.     printf( "0 = BLACK\n" );
  33.     printf( "1 = PURPLE\n" );
  34.     printf( "2 = BLUE\n" );
  35.     printf( "3 = GREEN\n" );
  36.     printf( "4 = ORANGE\n" );
  37.     printf( "5 = WHITE\n" );
  38.     printf( "\nPRESS ANY KEY TO CONTINUE (Q=QUIT)\n" );
  39.  
  40.     cmd = getc( stdin );                        /* get first command */
  41.  
  42.     hr_init();                                    /* switch to graphics */
  43.     hr_clear( sop , eop , HR_BLACK );            /* clear page to black */
  44.  
  45.     /* until QUIT, execute the command and get next command.
  46.        Each command is identified as its ASCII decimal value */
  47.  
  48.     while ( cmd != 81 )                            /* quit on ASCII Q */
  49.  
  50.     {    switch ( cmd )
  51.  
  52.         {    case 72:                            /* ASCII H - help */
  53.             {    hr_quit();                        /* switch to text */
  54.                 cmd = getc( stdin );            /* wait for key press */
  55.                 hr_init();                        /* switch to graphics */
  56.                 break;
  57.             }
  58.  
  59.             case 8:                                /* ASCII left arrow */
  60.             {    x = ( x > 0 ) ? --x : x;        /* decrement column, not < 0 */
  61.                 hr_pixel( x , y , clr , sop , eop );         /* set pixel */
  62.                 break;
  63.             }
  64.  
  65.             case 21:                            /* ASCII right arrow */
  66.             {    x = ( x < 279 ) ? ++x : x;        /* increment col, not > 279 */
  67.                 hr_pixel( x , y , clr , sop , eop );        /* set pixel */
  68.                 break;
  69.             }
  70.  
  71.             case 10:                            /* ASCII down arrow */
  72.             {    y = ( y < 191 ) ? ++y : y;        /* incrment row, not > 191 */
  73.                 hr_pixel( x , y , clr , sop , eop );        /* set pixel */
  74.                 break;
  75.             }
  76.  
  77.             case 11:                            /* ASCII up arrow */
  78.             {    y = ( y > 0 ) ? --y : y;        /* decrement row, not < 0 */
  79.                 hr_pixel( x , y , clr , sop , eop );        /* set pixel */
  80.                 break;
  81.             }
  82.  
  83.             case 67:                            /* ASCII C - clear page */
  84.             {    hr_clear( sop , eop , clr );    /* current page and color */
  85.                 break;
  86.             }
  87.  
  88.             case 48:                            /* ASCII zero */
  89.             {    clr = HR_BLACK;                    /* set color to black */
  90.                 break;
  91.             }
  92.  
  93.             case 49:                            /* ASCII one */
  94.             {    clr = HR_PURPLE;                /* set color to purple */
  95.                 break;
  96.             }
  97.  
  98.             case 50:                            /* ASCII two */
  99.             {    clr = HR_BLUE;                    /* set color to blue */
  100.                 break;
  101.             }
  102.  
  103.             case 51:                            /* ASCII three */
  104.             {    clr = HR_GREEN;                    /* set color to green */
  105.                 break;
  106.             }
  107.  
  108.             case 52:                            /* ASCII four */
  109.             {    clr = HR_ORANGE;                /* set color to orange */
  110.                 break;
  111.             }
  112.  
  113.             case 53:                            /* ASCII five */
  114.             {    clr = HR_WHITE;                    /* set color to white */
  115.                 break;
  116.             }
  117.  
  118.             default:
  119.                 break;                            /* disregard other values */
  120.  
  121.         }                                        /* end switch( cmd ) */
  122.  
  123.         cmd = getc( stdin );                    /* get next command */
  124.  
  125.     }                                            /* end while */
  126.  
  127.      hr_quit();                                    /* make sure we will exit
  128.                                                    the program in text mode */
  129.  
  130.     cmd = ioctl( stdin , KB_CLEAR );            /* clear the screen */
  131.     cmd = ioctl( stdin , KB_ECHO , 1 );            /* enable keyboard echo */
  132.  
  133.     exit();
  134. }
  135.  
  136.