Borland C++ reference

setcolor

raw OCR

Sets the current drawing color using the palette.

Defined in header <graphics.h>

Syntax

#include <graphics.h>
void far setcolor(int color);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor.

The current drawing color is the value to which pixels are set when lines, and so on are drawn. The following tables show the drawing colors available for the CGA and EGA, respectively.

Constantassigned to colornumber (pixel value) Palette

number123
0CGA_LIGHTGREENCGA_LIGHTRED CGA_YELLOW
1CGA_LIGHTCYANCGA__LIGHTMAGENTA CGA_WHITE
2CGA_GREENCGA__RED CGA_BROWN
3CGA_CYANCGA.MAGENTA CGA_LIGHTGRAY
NumericvalueSymbolic name
0BLACK8DARKGRAY
1BLUE9LIGHTBLUE
2GREEN10LIGHTGREEN
3CYAN11LIGHTCYAN
4RED12LIGHTRED
5MAGENTA13LIGHTMAGENTA
BROWN14YELLOW
LIGHTGRAY15WHITE

You select a drawing color by passing either the color number itself or the equivalent symbolic name to setcolor. For example, in CGACO mode, the palette contains four colors: the background color, light green, light red, and yellow. In this mode, either setcolor(3) or setcolor(CGA_YELLOW) selects a drawing color of yellow.

Return value

None.

See also

Example

*include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
   /* select driver and mode that supports multiple drawing  colors */
   int gdriver = EGA, gmode = EGAHI, errorcode;
   int color, maxcolor, x, y;
   char msg[80];
   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)    /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg (errorcode));
      printf("Press any key to halt:");
      getchO ;
      exit(l);               /* terminate with an error code  */

   /* maximum color index supported */
   maxcolor = getmaxcolor();
   /* for centering text messages */
   settextjustify(CENTER„TEXT, CENTER_TEXT);
   X = getmaxx() / 2;
   y = getmaxy() / 2;
   /* loop through the available colors */
   for (color=l; color<=maxcolor; color++) {
      cleardevice();         /* clear the screen */
      setcolor(color);       /* select new background color */

      /* output a messsage */
   sprintf(msg, "Color: %d", color)
   outtextxy(x, y, msg);
   getchO ;
}
/* clean up */
closegraphO ;
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.