C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
STAR.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* STAR.C illustrates functions:                              (DOS-only)
 *      _polygon        _getwritemode       _setwritemode
 */
 
#include <conio.h>
#include <stdlib.h>
#include <graph.h>
#include <math.h>
#include <stdlib.h>
 
short wmodes[5]  = { _GPSET,   _GPRESET, _GXOR,    _GOR,     _GAND    };
char *wmstr[5]   = { "PSET  ", "PRESET", "XOR   ", "OR    ", "AND   " };
 
void star( double centerx, double centery, double radius,
           int writemode, int fill );
 
void main()
{
    short i, tcolor;
    double x, y;
 
    if( !_setvideomode( _MAXCOLORMODE ) )    /* Find valid graphics mode */
        exit( 1 );
 
    _setwindow( 0, -50.0, -40.0, 50.0, 40.0 );
 
    x = y = -10.0;
    star( x, y, 25.0, _GPSET, _GFILLINTERIOR );
    _getch();
    tcolor = _getcolor();
    _setcolor( 2 );
    _floodfill_w( x, y, tcolor );
 
    for( i = 0; i < 5; i++ )
    {
        _settextposition( 1, 1 );
        _outtext( wmstr[i] );
        star( x += 2.0, y += 1.5, 25.0, wmodes[i], _GBORDER );
        _getch();
    }
    _setvideomode( _DEFAULTMODE );
}
 
#define PI 3.1415
void star( double centerx, double centery, double radius,
           int writemode, int fill )
{
    int    wm, side;
    struct _wxycoord polyside[5];
    double radians;
 
    /* Save write mode and set new. */
    wm = _getwritemode();
    _setwritemode( writemode );
 
    /* Calculate points of star every 144 degrees, then connect them. */
    for( side = 0; side < 5; side++ )
    {
        radians = 144 * PI / 180;
        polyside[side].wx = centerx + (cos( side * radians ) * radius);
        polyside[side].wy = centery + (sin( side * radians ) * radius);
    }
    _polygon_wxy( fill, polyside, 5 );
 
    /* Restore original write mode. */
    _setwritemode( wm );
}
                                    -♦-