[C] 改变调色板的颜色 →→→→→进入此内容的聊天室

来自 , 2020-10-13, 写在 C, 查看 147 次.
URL http://www.code666.cn/view/229754d7
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. int main(void)
  7. {
  8.    /* request auto detection */
  9.    int gdriver = DETECT, gmode, errorcode;
  10.    int color, maxcolor, ht;
  11.    int y = 10;
  12.    char msg[80];
  13.  
  14.    /* initialize graphics and local variables */
  15.    initgraph(&gdriver, &gmode, "");
  16.  
  17.    /* read result of initialization */
  18.    errorcode = graphresult();
  19.    if (errorcode != grOk)  /* an error occurred */
  20.    {
  21.       printf("Graphics error: %s\n", grapherrormsg(errorcode));
  22.       printf("Press any key to halt:");
  23.       getch();
  24.       exit(1); /* terminate with an error code */
  25.    }
  26.  
  27.    maxcolor = getmaxcolor();
  28.    ht = 2 * textheight("W");
  29.  
  30.    /* display the default colors */
  31.    for (color=1; color<=maxcolor; color++)
  32.    {
  33.       setcolor(color);
  34.       sprintf(msg, "Color: %d", color);
  35.       outtextxy(1, y, msg);
  36.       y += ht;
  37.    }
  38.  
  39.    /* wait for a key */
  40.    getch();
  41.  
  42.    /* black out the colors one by one */
  43.    for (color=1; color<=maxcolor; color++)
  44.    {
  45.       setpalette(color, BLACK);
  46.       getch();
  47.    }
  48.  
  49.    /* clean up */
  50.    closegraph();
  51.    return 0;
  52. }

回复 "改变调色板的颜色"

这儿你可以回复上面这条便签

captcha