_setcolor

Description

Sets the current color.

#include <graph.h>

short __far _setcolor( short color );

color Desired color index  

Remarks

The _setcolor function sets the current color index to color. The color parameter is masked but always within range. The following graphics functions use the current color: _arc, _ellipse, _floodfill, _lineto, _outgtext, _pie, _polygon, _rectangle, and _setpixel.

The _setcolor function accepts a short value as an argument. It is a color index.

The default color index is the highest numbered color index in the current palette.

Note that the _setcolor function does not affect the output of the presentation-graphics functions.

Return Value

This function returns the previous color. If the function fails (e.g., if used in a text mode), it returns –1.

Compatibility

Standards:None

16-Bit:DOS

32-Bit:None

See Also

_arc functions, _ellipse functions, _floodfill, _getcolor, _lineto functions, _outgtext, _pie functions, _polygon functions, _rectangle functions, _selectpalette, _setpixel functions

Example

/* GPIXEL.C: This program assigns different colors to randomly

* selected pixels.

*/

#include <conio.h>

#include <stdlib.h>

#include <graph.h>

void main( void )

{

short xvar, yvar;

struct _videoconfig vc;

/* Find a valid graphics mode. */

if( !_setvideomode( _MAXCOLORMODE ) )

exit( 1 );

_getvideoconfig( &vc );

/* Draw filled ellipse to turn on certain pixels. */

_ellipse( _GFILLINTERIOR, vc.numxpixels / 6, vc.numypixels / 6,

vc.numxpixels / 6 * 5, vc.numypixels / 6 * 5 );

/* Draw random pixels in random colors... */

while( !_kbhit() )

{

/* ...but only if they are already on (inside the ellipse). */

xvar = rand() % vc.numxpixels;

yvar = rand() % vc.numypixels;

if( _getpixel( xvar, yvar ) != 0 )

{

_setcolor( rand() % 16 );

_setpixel( xvar, yvar );

}

}

_getch(); /* Throw away the keystroke. */

_setvideomode( _DEFAULTMODE );

exit( 0 );

}