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