home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c040 / 1.ddi / SAMPLES / GRDEMO.C$ / GRDEMO.bin
Encoding:
Text File  |  1990-02-27  |  19.1 KB  |  683 lines

  1. /* GRDEMO.C - Demonstrates capabilities of the Microsoft graphics library.
  2.  * Uses MENU module to display menus. Uses TURTLE module for Turtle
  3.  * graphics.
  4.  *
  5.  * If GRAPHICS.LIB was not included in your run-time libraries during
  6.  * setup, you must you must add it to the GRDEMO.MAK program list or
  7.  * give it on the QCL command line.
  8.  */
  9.  
  10. #include <graph.h>
  11. #include <math.h>
  12. #include <malloc.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <conio.h>
  16. #include <time.h>
  17. #include "turtle.h"
  18. #include "menu.h"
  19.  
  20. /* Function prototypes */
  21. int  main( void );
  22. void Circles( void );
  23. void Sphere( void );
  24. int  Polygons( void );
  25. int  Spiral( int angle, double inc );
  26. int  InSpiral( double side, int angle, int inc );
  27. void Bug( void );
  28. void Adjust( void );
  29. void Diamond( double xy );
  30.  
  31. /* Returns a random number between min and max, which must be in
  32.  * integer range.
  33.  */
  34. #define getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
  35.  
  36. /* Constants */
  37. #define PI      3.141593
  38. #define LASTATR 15
  39. #define NLASTATR 14
  40.  
  41. /* Array and enum for main menu */
  42. ITEM mnuMain[] =
  43. {                    /* Highlight Char  Pos */
  44.     { 0, "Quit"            },   /* Q     0  */
  45.     { 0, "Circles"         },   /* C     0  */
  46.     { 0, "Rotating Sphere" },   /* R     0  */
  47.     { 0, "Tunnel"          },   /* T     0  */
  48.     { 0, "Spiral"          },   /* S     0  */
  49.     { 0, "Inverted Spiral" },   /* I     0  */
  50.     { 0, "Bug"             },   /* B     0  */
  51.     { 0, "Adjust Window"   },   /* A     0  */
  52.     { 0, "Mode Change"     },   /* M     0  */
  53.     { 0, ""                }
  54. };
  55.  
  56. /* Define constants (0, 1, 2,...) for menu choices */
  57. enum CHOICES
  58. {
  59.     QUIT, CIRCLES, SPHERE, TUNNEL, SPIRAL, INSPIRAL, BUG, ADJUST, CHANGE
  60. };
  61.  
  62. /* Arrays of video mode menu items and of corresponding mode numbers.
  63.  * Each has a temporary array containing all items, and a pointer version
  64.  * including all except Olivetti.
  65.  */
  66. ITEM mnuModesT[] =
  67. {                    /* Highlight Char  Pos */
  68.     { 0, "ORESCOLOR "   },      /* O     0  */
  69.     { 4, "MRES4COLOR "  },      /* 4     4  */
  70.     { 4, "MRESNOCOLOR"  },      /* N     4  */
  71.     { 4, "HRESBW"       },      /* B     4  */
  72.     { 0, "MRES16COLOR"  },      /* M     0  */
  73.     { 0, "HRES16COLOR"  },      /* H     0  */
  74.     { 0, "ERESCOLOR"    },      /* E     0  */
  75.     { 4, "VRES2COLOR"   },      /* 2     4  */
  76.     { 0, "VRES16COLOR"  },      /* V     0  */
  77.     { 1, "MRES256COLOR" },      /* R     4  */
  78.     { 0, ""             }
  79. };
  80. ITEM *mnuModes = &mnuModesT[1];  /* Default is no Olivetti mode */
  81.  
  82. int aModesT[] =
  83. {
  84.     _ORESCOLOR,
  85.     _MRES4COLOR,
  86.     _MRESNOCOLOR,
  87.     _HRESBW,
  88.     _MRES16COLOR,
  89.     _HRES16COLOR,
  90.     _ERESCOLOR,
  91.     _VRES2COLOR,
  92.     _VRES16COLOR,
  93.     _MRES256COLOR,
  94.     _TEXTMONO,
  95.     _ERESNOCOLOR,
  96.     _HERCMONO
  97. };
  98. int *aModes = &aModesT[1];              /* Default is no Olivetti mode */
  99.  
  100. /* Global video configuration */
  101. struct videoconfig vc;
  102.  
  103. int main()
  104. {
  105.     int rowMid, colMid;
  106.     int fColor, fFirstTime = TRUE;
  107.     int iMode, iMainCur = 0, iModesCur = 0;
  108.  
  109.     _displaycursor( _GCURSOROFF );
  110.     _getvideoconfig( &vc );
  111.     rowMid = vc.numtextrows / 2;
  112.     colMid = vc.numtextcols / 2;
  113.  
  114.     /* Select best graphics mode, adjust menus, set color flag. Note
  115.      * that this requires checking both the adapter and the mode.
  116.      */
  117.     switch( vc.adapter )
  118.     {
  119.         case _OCGA:
  120.             mnuModes = &mnuModesT[0];           /* Turn on Olivetti mode */
  121.             aModes = &aModesT[0];
  122.         case _CGA:
  123.             mnuModesT[4].achItem[0] = '\0';     /* Turn off EGA modes    */
  124.             iMode = _MRES4COLOR;
  125.             break;
  126.         case _HGC:
  127.             mnuModesT[7].achItem[0] = '\0';
  128.             iMode = _HERCMONO;
  129.             break;
  130.         case _OEGA:
  131.             mnuModes = &mnuModesT[0];           /* Turn on Olivetti mode */
  132.             aModes = &aModesT[0];
  133.         case _EGA:
  134.             mnuModesT[7].achItem[0] = '\0';     /* Turn off VGA modes    */
  135.             if( vc.memory > 64 )
  136.                 iMode = _ERESCOLOR;
  137.             else
  138.                 iMode = _HRES16COLOR;
  139.             break;
  140.         case _OVGA:
  141.             mnuModes = &mnuModesT[0];           /* Turn on Olivetti mode */
  142.             aModes = &aModesT[0];
  143.         case _VGA:
  144.             iMode = _VRES16COLOR;
  145.             break;
  146.         case _MCGA:
  147.             iMode = _MRES256COLOR;
  148.             break;
  149.         case _MDPA:
  150.         default:
  151.             puts( "No graphics mode available.\n" );
  152.             return TRUE;
  153.     }
  154.     switch( vc.mode )
  155.     {
  156.         case _TEXTBW80:
  157.         case _TEXTBW40:
  158.             fColor = FALSE;
  159.             break;
  160.         case _TEXTMONO:
  161.         case _ERESNOCOLOR:
  162.         case _HERCMONO:
  163.             fColor = FALSE;
  164.             if( iMode != _HERCMONO )
  165.                 iMode = _ERESNOCOLOR;
  166.             mnuMain[8].achItem[0] = '\0';       /* Turn off mode change */
  167.             break;
  168.         default:
  169.             fColor = TRUE;
  170.             break;
  171.     }
  172.  
  173.     /* Find current mode in mode array. */
  174.     for( iModesCur = 0; aModes[iModesCur] != iMode; iModesCur++ )
  175.         ;
  176.  
  177.     /* Seed randomizer with time. */
  178.     srand( (unsigned)time( NULL ) );
  179.  
  180.     while( TRUE )
  181.     {
  182.         /* Set text mode and optionally clear the screen to blue. */
  183.         _setvideomode(_DEFAULTMODE );
  184.         if( fColor )
  185.             _setbkcolor( (long)_TBLUE );
  186.         _clearscreen( _GCLEARSCREEN );
  187.  
  188.         /* Select from menu. */
  189.         iMainCur = Menu( rowMid, colMid, mnuMain, iMainCur );
  190.  
  191.         /* Set graphics mode and initialize turtle graphics. Put border
  192.          * on window.
  193.          */
  194.         if( iMainCur != CHANGE )
  195.         {
  196.             _setvideomode( iMode );
  197.             _displaycursor( _GCURSOROFF );
  198.             _getvideoconfig( &vc );
  199.             InitTurtle( &vc );
  200.             Rectangle( 2 * tc.xMax, 2 * tc.yMax );
  201.         }
  202.  
  203.         /* Branch to menu choice. */
  204.         switch( iMainCur )
  205.         {
  206.             case QUIT:
  207.                 _setvideomode( _DEFAULTMODE );
  208.                 return FALSE;
  209.             case CIRCLES:
  210.                 Circles();
  211.                 break;
  212.             case SPHERE:
  213.                 Sphere();
  214.                 break;
  215.             case TUNNEL:
  216.                 PenDown( FALSE );
  217.                 MoveTo( -tc.xMax * .2, tc.yMax * .15 );
  218.                 PenDown( TRUE );
  219.                 Polygons();
  220.                 while( !ClickOrPress() )
  221.                     NextColorValue( DEFAULT );   /* Rotate palette */
  222.                 break;
  223.             case SPIRAL:
  224.                 if( Spiral( getrandom( 30, 80 ), (double)getrandom( 1, 5 ) ) )
  225.                     break;
  226.                 while( !ClickOrPress() )
  227.                     NextColorValue( DEFAULT );
  228.                 break;
  229.             case INSPIRAL:
  230.                 NextColorIndex( 0 );
  231.                 if( InSpiral( (double)getrandom( 8, 20 ),
  232.                               getrandom( 4, 22 ),
  233.                               getrandom( 3, 31 ) ) )
  234.                     break;
  235.                 while( !ClickOrPress() )
  236.                     NextColorValue( DEFAULT );
  237.                 break;
  238.             case BUG:
  239.                 Bug();
  240.                 break;
  241.             case ADJUST:
  242.                 Adjust();
  243.                 continue;
  244.             case CHANGE:
  245.                 if( fColor )
  246.                     _setbkcolor( (long)_TBLUE );
  247.                 _clearscreen( _GCLEARSCREEN );
  248.  
  249.                 iModesCur = Menu( rowMid, colMid, mnuModes, iModesCur );
  250.                 iMode = aModes[iModesCur];
  251.                 if( vc.adapter == _MCGA )
  252.                     switch( iMode )
  253.                     {
  254.                         case _MRES16COLOR:
  255.                         case _HRES16COLOR:
  256.                         case _ERESCOLOR:
  257.                         case _VRES16COLOR:
  258.                             _settextposition( 1, 22 );
  259.                             _outtext( "Mode not recognized" );
  260.                             iMode = _MRES256COLOR;
  261.                     }
  262.                 break;
  263.         }
  264.     }
  265. }
  266.  
  267. /* Circles - Draw circles of varying sizes and colors on screen in a
  268.  * round pattern.
  269.  *
  270.  * Params: None
  271.  *
  272.  * Return: None
  273.  *
  274.  * Uses:   tc
  275.  */
  276. void Circles()
  277. {
  278.     double x, y, xyRadius;
  279.     int fFill, fPenDown;
  280.  
  281.     /* Initialize and save pen and fill flags. */
  282.     if( tc.cci <= 4 )
  283.         fFill = SetFill( FALSE );
  284.     else
  285.         fFill = SetFill( TRUE );
  286.     fPenDown = PenDown( FALSE );
  287.  
  288.     while( TRUE )
  289.     {
  290.         /* Draw circles. */
  291.         for( xyRadius = 10.0; xyRadius <= 130.0; xyRadius++ )
  292.         {
  293.             x = (tc.xMax - 30) * atan( sin( xyRadius / PI ) );
  294.             y = (tc.yMax - 30) * atan( cos( xyRadius / PI ) );
  295.             MoveTo( x, y );
  296.             PenColor( NextColorIndex( DEFAULT ) );
  297.             Circle( xyRadius );
  298.             if( ClickOrPress() )
  299.             {
  300.                 PenDown( fPenDown );
  301.                 SetFill( fFill );
  302.                 return;
  303.             }
  304.         }
  305.  
  306.         /* For palette modes (except 256 color), start over. */
  307.         if( tc.ccv == 64 || tc.ccv == 16 )
  308.         {
  309.             _clearscreen( _GCLEARSCREEN );
  310.             SetFill( FALSE );
  311.             MoveTo( 0.0, 0.0 );
  312.             PenColor( WHITE );
  313.             Rectangle( 2 * tc.xMax, 2 * tc.yMax );
  314.             SetFill( fFill );
  315.             NextColorValue( DEFAULT );
  316.         }
  317.     }
  318. }
  319.  
  320. /* Sphere - Draw and fill slices of a sphere. Rotate colors in EGA+ modes
  321.  * with more than 4 color indexes.
  322.  *
  323.  * Params: None
  324.  *
  325.  * Return: None
  326.  *
  327.  * Uses:   tc
  328.  */
  329. void Sphere()
  330. {
  331.     double xCur, xSize, ySize, xInc;
  332.     short ciBorder, fFill;
  333.  
  334.     ySize = xSize = tc.yMax * 0.9 * 2;
  335.     fFill = SetFill( FALSE );
  336.     NextColorIndex( 0 );
  337.     xInc = xSize / 14;
  338.     ciBorder = PenColor( DEFAULT );
  339.     BorderColor( ciBorder );
  340.  
  341.     /* Draw slices. */
  342.     for( xCur = xInc; xCur <= xSize; xCur += xInc * 2 )
  343.         Ellipse( xCur, ySize );
  344.     SetFill( TRUE );
  345.     PenDown( FALSE );
  346.     Turn( 90 );
  347.     xSize /= 2;
  348.     MoveTo( xSize - xInc, 0.0 );
  349.  
  350.     NextColorValue( LIMITED );
  351.  
  352.     /* Fill slices. */
  353.     while( tc.xCur >= (-xSize + xInc))
  354.     {
  355.         PenColor( NextColorIndex( DEFAULT ) );
  356.         FillIn();
  357.         Move( -xInc );
  358.     }
  359.  
  360.     while( !GetKey( NO_WAIT ) )
  361.         NextColorValue( LIMITED );
  362.  
  363.     PenDown( TRUE );
  364.     SetFill( fFill );
  365. }
  366.  
  367. /* Polygons - Draws polygons (starting with triangle) of increasing
  368.  * size by incrementing the number of sides without changing the
  369.  * length of sides. Make sure pen is down.
  370.  *
  371.  * Params: None
  372.  *
  373.  * Return: 1 for user interrupt, 0 for edge of screen encountered
  374.  *
  375.  * Uses:   tc
  376.  */
  377. int Polygons()
  378. {
  379.     int cSides = 3, atrib = 1;
  380.     double dxy = tc.yUnit;
  381.  
  382.     while( TRUE )
  383.     {
  384.         PenColor( NextColorIndex( DEFAULT ) );
  385.         if( !Poly( cSides++, dxy += 1.5 ) )
  386.             return FALSE;
  387.         if( ClickOrPress() )
  388.             return TRUE;
  389.     }
  390. }
  391.  
  392. /* Spiral - Draw a spiral by incrementing the length of each side
  393.  * of a rotating figure.
  394.  *
  395.  * Params: ang - determines tightness
  396.  *         xyInc - determines size of sides
  397.  *
  398.  * Return: 1 for user interrupt, 0 for edge of screen encountered
  399.  *
  400.  * Uses:   tc
  401.  */
  402. int Spiral( int ang, double xyInc )
  403. {
  404.     double xy = tc.yUnit;
  405.  
  406.     while( TRUE )
  407.     {
  408.         PenColor( NextColorIndex( DEFAULT ) );
  409.         if( !Move( xy += xyInc ) )
  410.             return FALSE;
  411.         Turn( ang );
  412.         if( ClickOrPress() )
  413.             return TRUE;
  414.     }
  415. }
  416.  
  417. /* InSpiral - Draw an inverted spiral by increasing each angle
  418.  * of a rotating figure while keeping the length of sides constant.
  419.  *
  420.  * Params: xy - determines size
  421.  *         ang - initial angle determines shape
  422.  *         angInc - determines tightness and shape
  423.  *
  424.  * Return: 1 for user interrupt, 0 for edge of screen encountered
  425.  */
  426. int InSpiral( double xy, int ang, int angInc )
  427. {
  428.     while( TRUE )
  429.     {
  430.         PenColor( NextColorIndex( DEFAULT ) );
  431.         if( !Move( xy ) )
  432.             return FALSE;
  433.         Turn( ang += angInc );
  434.         if( ClickOrPress())
  435.             return TRUE;
  436.     }
  437. }
  438.  
  439. /* Bug - Draws a winged bug on the screen. Then moves it randomly
  440.  * around the screen.
  441.  *
  442.  * Params: None
  443.  *
  444.  * Return: None
  445.  *
  446.  * Uses:   tc
  447.  */
  448. void Bug()
  449. {
  450.  
  451.     static unsigned char uTopWing[] = { 0x81, 0x3c, 0xc3, 0x66,
  452.                                         0x66, 0x0f, 0xf0, 0x18 };
  453.     static unsigned char uBotWing[] = { 0x66, 0x0f, 0xf0, 0x18,
  454.                                         0x81, 0x3c, 0xc3, 0x66 };
  455.     char *buffer;               /* Buffer for image */
  456.  
  457.     /* Draw bug. */
  458.     PenDown( FALSE );
  459.     SetFill( TRUE );
  460.     Move( 40.0 );               /* Draw and fill front wings */
  461.     Turn( 90 );
  462.     Move( 80.0 );
  463.     PenColor( 1 );
  464.     _setfillmask( uTopWing );
  465.     Ellipse( 172.0, 70.0 );
  466.     Turn( 180 );
  467.     Move( 160.0 );
  468.     Ellipse( 172.0, 70.0 );
  469.     Turn(-90 );
  470.     MoveTo( 0.0, 0.0 );
  471.     Move( 25.0 );               /* Draw and fill back wings */
  472.     Turn( 90 );
  473.     Move( 70.0 );
  474.     PenColor( 2 );
  475.     _setfillmask( uBotWing );
  476.     Ellipse( 150.0, 70.0 );
  477.     Turn( 180 );
  478.     Move( 140.0 );
  479.     Ellipse( 150.0, 70.0 );
  480.     Turn(-90 );
  481.     MoveTo( 0.0, 0.0 );
  482.     _setfillmask( NULL );       /* Draw body */
  483.     PenColor( 3 );
  484.     BorderColor( 3 );
  485.     Ellipse( 52.0, 220.0 );
  486.     PenColor( 1 );              /* Drill eyes */
  487.     BorderColor( 1 );
  488.     SetFill( FALSE );
  489.     Move( 90.0 );
  490.     Turn( 90 );
  491.     Move( 22.0 );
  492.     Circle( 20.0 );
  493.     PenColor( 0 );
  494.     FillIn();
  495.     PenColor( 1 );
  496.     Turn( 180 );
  497.     Move( 44.0 );
  498.     Circle( 20.0 );
  499.     PenColor( 0 );
  500.     FillIn();
  501.  
  502.     /* Move into position - top-right of image. */
  503.     MoveTo( 0.0, 0.0 );
  504.     TurnTo( 0 );
  505.     Move( 120.0 );
  506.     Turn( -90 );
  507.     Move( 175.0 );
  508.     Turn( 90 );
  509.  
  510.     /* Size image and allocate memory for it. */
  511.     buffer = (char *)malloc( (size_t)ImageSize( 350.0, 240.0 ) );
  512.     GetImage( 350.0, 240.0, buffer );
  513.  
  514.     /* Move randomly, adjusting at edges. */
  515.     while( !ClickOrPress() )
  516.     {
  517.         if( tc.xCur <= (-tc.xMax + 15.0) )
  518.             TurnTo( 90 );
  519.         else if( tc.yCur <= (-tc.yMax + 15.0) )
  520.             TurnTo( 180 );
  521.         else if( tc.xCur >= (tc.xMax - 365.0) )
  522.             TurnTo( 270 );
  523.         else if( tc.yCur >= (tc.yMax - 255.0) )
  524.             TurnTo( 0 );
  525.         else
  526.             Turn( getrandom( -20, 20 ) );
  527.         Move( 3.0 );
  528.         PutImage( buffer, _GPSET );
  529.     }
  530.     free( (char *)buffer );
  531. }
  532.  
  533. /* Adjust - Allow the user to interactively adjust the display window.
  534.  * Unshifted direction keys adjust the window size. Shifted direction
  535.  * keys move the window. The numeric keypad plus and minus keys adjust
  536.  * aspect without changing the window. A window frame and a diamond give
  537.  * visual feedback on adjustments.
  538.  *
  539.  * Params: None
  540.  *
  541.  * Return: None
  542.  *
  543.  * Uses:   tc and vc
  544.  */
  545. #define WININC 4
  546. void Adjust()
  547. {
  548.     short i, iWriteMode;
  549.     double xyRadius = 400.0, xEdge, yEdge;
  550.     char achT[40];
  551.  
  552.     /* Display instructions. */
  553.     _clearscreen( _GCLEARSCREEN );
  554.     _settextposition( 2, 2 );
  555.     _outtext(" Grey PLUS and MINUS Adjust aspect" );
  556.     _settextposition( 3, 2 );
  557.     _outtext(" Cursor keys         Size window" );
  558.     _settextposition( 4, 2 );
  559.     _outtext(" SHIFT cursor keys   Move window" );
  560.     _settextposition( 5, 2 );
  561.     _outtext(" ENTER               Finished" );
  562.  
  563.     /* Save old write mode and set XOR so you can erase figures by
  564.      * redrawing. This allows lines to overwrite text without erasing.
  565.      */
  566.     iWriteMode = _getwritemode();
  567.     _setwritemode( _GXOR );
  568.  
  569.     while( TRUE )
  570.     {
  571.         /* Display data. */
  572.         _settextposition( 6, 2 );
  573.         sprintf( achT, " ratio=%1.2f  xMax=%.f  yMax=%.f",
  574.                  tc.yxRatio, tc.xMax, tc.yMax );
  575.         _outtext( achT );
  576.  
  577.         /* Calculate current box edges. */
  578.         xEdge = 2 * tc.xMax;
  579.         yEdge = 2 * tc.yMax;
  580.  
  581.         /* Draw border rectangle and diamond that illustrates ratio. */
  582.         Rectangle( xEdge, yEdge );
  583.         Diamond( xyRadius );
  584.  
  585.         switch( GetKey( CLEAR_WAIT ) )
  586.         {
  587.             /* Adjust aspect. */
  588.             case N_MINUS:
  589.                 if( tc.yxRatio > 0.4 )
  590.                     tc.yxRatio = (tc.xMax - (WININC * tc.yUnit)) / tc.yMax;
  591.                 break;
  592.             case N_PLUS:
  593.                 if( tc.yxRatio < 8.0 )
  594.                     tc.yxRatio = (tc.xMax + (WININC * tc.yUnit)) / tc.yMax;
  595.                 break;
  596.  
  597.             /* Adjust window size. */
  598.             case U_RT:
  599.                 if( tc.xsLeft < (vc.numxpixels / 3) )
  600.                     tc.xsLeft += WININC;
  601.                 if( tc.xsRight > (vc.numxpixels - (vc.numxpixels / 3)) )
  602.                     tc.xsRight -= WININC;
  603.                 break;
  604.             case U_LT:
  605.                 if( tc.xsLeft )
  606.                     tc.xsLeft -= WININC;
  607.                 if( tc.xsRight < vc.numxpixels )
  608.                     tc.xsRight += WININC;
  609.                 break;
  610.             case U_DN:
  611.                 if( tc.ysTop < (vc.numypixels / 3) )
  612.                     tc.ysTop += WININC;
  613.                 if( tc.ysBot > (vc.numypixels - (vc.numypixels / 3)) )
  614.                     tc.ysBot -= WININC;
  615.                 break;
  616.             case U_UP:
  617.                 if( tc.ysTop )
  618.                     tc.ysTop -= WININC;
  619.                 if( tc.ysBot < vc.numypixels )
  620.                     tc.ysBot += WININC;
  621.                 break;
  622.  
  623.             /* Adjust window position. */
  624.             case S_LT:
  625.                 if( tc.xsLeft )
  626.                 {
  627.                     tc.xsLeft -= WININC;
  628.                     tc.xsRight -= WININC;
  629.                 }
  630.                 break;
  631.             case S_RT:
  632.                 if( tc.xsRight < vc.numxpixels )
  633.                 {
  634.                     tc.xsLeft += WININC;
  635.                     tc.xsRight += WININC;
  636.                 }
  637.                 break;
  638.             case S_UP:
  639.                 if( tc.ysTop )
  640.                 {
  641.                     tc.ysTop -= WININC;
  642.                     tc.ysBot -= WININC;
  643.                 }
  644.                 break;
  645.             case S_DN:
  646.                 if( tc.ysBot < vc.numypixels )
  647.                 {
  648.                     tc.ysTop += WININC;
  649.                     tc.ysBot += WININC;
  650.                 }
  651.                 break;
  652.  
  653.             /* Finished. */
  654.             case ENTER:
  655.                 _setwritemode( iWriteMode );
  656.                 return;
  657.  
  658.             /* Ignore unknown key. */
  659.             default:
  660.                 break;
  661.         }
  662.         /* Redraw figures to erase them. Reset defaults. */
  663.         Rectangle( xEdge, yEdge );
  664.         Diamond( xyRadius );
  665.         Home();
  666.     }
  667. }
  668.  
  669. /* Routine used by Adjust to draw its diamond. */
  670. void Diamond( double xy )
  671. {
  672.         PenDown( FALSE );
  673.         MoveTo( 0.0, xy );
  674.         PenDown( TRUE );
  675.         MoveTo( xy, 0.0 );
  676.         MoveTo( 0.0, -xy );
  677.         MoveTo( -xy, 0.0 );
  678.         MoveTo( 0.0, xy );
  679.         PenDown( FALSE );
  680.         MoveTo( 0.0, 0.0 );
  681.         PenDown( TRUE );
  682. }
  683.