home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv2_5 / msc5 / gdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  2.6 KB  |  115 lines

  1. /*
  2. Microsoft Systems Journal
  3. Volume 2; Issue 5; November, 1987
  4.  
  5. Code Listings For:
  6.  
  7.     GDEMO
  8.     pp. 67-76
  9.  
  10. Author(s): Augie Hansen
  11. Title:     Microsoft C Optimizing Compiler 5.0 Offers Improved Speed and 
  12.            Code Size
  13.  
  14.  
  15.  
  16.  
  17.  
  18. Figure 5
  19. ========
  20.  
  21. */
  22.  
  23. /********************************************************************
  24. * NAME: gdemo
  25. *
  26. * DESCRIPTION: This is a simple graphics demonstration program.  Its
  27. *  purpose it to show how to select a graphics mode, do some simple
  28. *  graphics work, and then return to DOS after restoring the user's
  29. *  previous video environment.
  30. ********************************************************************/
  31.  
  32. #include <graph.h>
  33. #include <math.h>
  34.  
  35. #define RHEIGHT         160
  36. #define RWIDTH          300
  37. #define MSG_ROW         25
  38. #define MSG_COL         8
  39. #define M_NOWAIT        0
  40. #define M_WAIT          1
  41.  
  42. /*
  43.  * Macro to plot points with the normal sense of the y axis.  The
  44.  * graphics library default is inverted (y increases in value moving
  45.  * down the screen).
  46.  */
  47.  
  48. #define PLOT(x_, y_)    _setpixel((x_), -(y_))
  49.  
  50. extern void Message(short, short, char *, short);
  51.  
  52. int
  53. main()
  54. {
  55.     struct videoconfig config;  /* video configuration data */
  56.     short x_org, y_org;         /* coordinates of the origin */
  57.     short x_ul, y_ul;           /* upper-left corner */
  58.     short x_lr, y_lr;           /* lower-right corner */
  59.     short x, y;
  60.  
  61.     static char prompt[] = { "Press a key to continue..." };
  62.  
  63.     /*
  64.      * Set up the medium-resloution graphics screen and set
  65.      * the logical origin to the center of the screen.
  66.      */
  67.  
  68.     _setvideomode(_MRES16COLOR);
  69.     _getvideoconfig(&config);
  70.     x_org = config.numxpixels / 2 - 1;
  71.     y_org = config.numypixels / 2 - 1;
  72.     _setlogorg(x_org, y_org);
  73.  
  74.     /*
  75.      * Draw a border rectangle and coordinate system.
  76.      */
  77.  
  78.     x_ul = -RWIDTH / 2;
  79.     y_ul = RHEIGHT / 2;
  80.     x_lr = RWIDTH / 2;
  81.     y_lr = -RHEIGHT / 2;
  82.     _rectangle(_GBORDER, x_ul, y_ul, x_lr, y_lr);
  83.     _moveto(x_ul, 0);
  84.     _lineto(x_lr, 0);
  85.     _moveto(0, y_ul);
  86.     _lineto(0, y_lr);
  87.  
  88.     /*
  89.      * Plot some curves.
  90.      */
  91.  
  92.     for (x = -100; x <= 100; ++x) {
  93.     y = x / 2;
  94.     PLOT(x, y);
  95.     }
  96.     Message(11, 27, "y = x / 2", M_NOWAIT);
  97.     for (x = -20; x <= 20; ++x) {
  98.     y = (x * x / 3) - 75;
  99.     PLOT(x, y);
  100.     }
  101.     Message(22, 3, "y = x**2 / 3 - 75", M_NOWAIT);
  102.  
  103.     /*
  104.      * Wait for the user's command to continue.
  105.      */
  106.     Message(MSG_ROW, MSG_COL, prompt, M_WAIT);
  107.  
  108.     /*
  109.      * Restore the original video mode.
  110.      */
  111.     _setvideomode(_DEFAULTMODE);
  112.  
  113.     return (0);
  114. }
  115.