[C] 定义IBM8514图形卡的颜色 →→→→→进入此内容的聊天室

来自 , 2019-10-20, 写在 C, 查看 111 次.
URL http://www.code666.cn/view/5f6371c9
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. int main(void)
  7. {
  8.    /* select a driver and mode that supports the use */
  9.    /* of the setrgbpalette function.                 */
  10.    int gdriver = VGA, gmode = VGAHI, errorcode;
  11.    struct palettetype pal;
  12.    int i, ht, y, xmax;
  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.    /* grab a copy of the palette */
  28.    getpalette(&pal);
  29.  
  30.    /* create gray scale */
  31.    for (i=0; i<pal.size; i++)
  32.       setrgbpalette(pal.colors[i], i*4, i*4, i*4);
  33.  
  34.    /* display the gray scale */
  35.    ht = getmaxy() / 16;
  36.    xmax = getmaxx();
  37.    y = 0;
  38.    for (i=0; i<pal.size; i++)
  39.    {
  40.       setfillstyle(SOLID_FILL, i);
  41.       bar(0, y, xmax, y+ht);
  42.       y += ht;
  43.    }
  44.  
  45.    /* clean up */
  46.    getch();
  47.    closegraph();
  48.    return 0;
  49. }

回复 "定义IBM8514图形卡的颜色"

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

captcha