User Tools

Site Tools


c:graphics.h:setpalette

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:graphics.h:setpalette [2024/02/16 01:05] (current)
Line 1: Line 1:
 +===== setpalette =====
 +
 +====Syntax of setpalette====
 +<code c>
 +      #include <graphics.h>
 +      void setpalette(int colornum, int color);
 +</code>
 +
 +
 +==== Description of setpalette  ==== 
 +<code c>
 +      setpalette changes the colornum entry in the palette to color. For
 +      example, setpalette(0,5) changes the first color in the current palette
 +      (the background color) to actual color number 5. If size is the number of
 +      entries in the current palette, colornum can range between 0 and (size -
 +      1).
 +      You can partially (or completely) change the colors in the EGA/VGA
 +      palette with setpalette. On a CGA, you can only change the first entry in
 +      the palette (colornum equals 0, the background color) with a call to
 +      setpalette.
 +      The color parameter passed to setpalette can be represented by symbolic
 +      constants which are defined in graphics.h.
 +      Name         Value
 +      BLACK        0
 +      BLUE         1
 +      GREEN        2
 +      CYAN         3
 +      RED          4
 +      MAGENTA      5
 +      BROWN        6
 +      LIGHTGRAY    7
 +      DARKGRAY     8
 +      LIGHTBLUE    9
 +      LIGHTGREEN   10
 +      LIGHTCYAN    11
 +      LIGHTRED     12
 +      LIGHTMAGENTA 13
 +      YELLOW       14
 +      WHITE        15
 +      setpalette cannot be used with the IBM-8514 driver; use setrgbpalette
 +      instead.
 +</code>
 +
 +
 +==== Example of setpalette ====
 +<code c>
 +      /* setpalette example */
 +
 +      #include <graphics.h>
 +      #include <stdlib.h>
 +      #include <stdio.h>
 +      #include <conio.h>
 +
 +      int main(void)
 +      {
 +         /* request autodetection */
 +         int gdriver = DETECT, gmode, errorcode;
 +         int color, maxcolor, ht;
 +         int y = 10;
 +         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:");
 +            getch();
 +            exit(1);               /* terminate with an error code */
 +         }
 +
 +         maxcolor = getmaxcolor();
 +         ht = 2 * textheight("W");
 +
 +         /* display the default colors */
 +         for (color=1; color<=maxcolor; color++) {
 +            setcolor(color);
 +            sprintf(msg, "Color: %d", color);
 +            outtextxy(1, y, msg);
 +            y += ht;
 +         }
 +
 +         /* wait for a key */
 +         getch();
 +
 +         /* black out the colors one by one */
 +         for (color=1; color<=maxcolor; color++) {
 +
 +            setpalette(color, BLACK);
 +            getch();
 +         }
 +
 +         /* clean up */
 +         closegraph();
 +         return 0;
 +      }
 +</code>
 +
 +
 +==== See also ====
 +[[setrgbpalette]]
 +
 +
 +===== output of setpalette example ===== 
 +
 +    no output of example at the moment
 +    do not hesitate and add it...  
 +
 +
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/graphics.h/setpalette.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz