📜  C语言中的setcolor函数

📅  最后修改于: 2021-05-25 19:10:47             🧑  作者: Mango

头文件graphics.h包含setcolor()函数,该函数用于将当前图形颜色设置为新颜色。
句法 :

void setcolor(int color);

说明:在“图形”中,为每种颜色分配了一个数字。可用颜色的总数为16。可用颜色的数量取决于当前的图形模式和驱动程序。例如,setcolor(RED)或setcolor(4)会将当前图形颜色更改为RED。请记住,默认绘图颜色为白色。颜色表如下所示。

COLOR               INT VALUES
-------------------------------
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

下面是setcolor()函数。

// C Implementation for setcolor()
#include 
#include 
  
// driver code
int main()
{
    // gm is Graphics mode which is
    // a computer display mode that
    // generates image using pixels.
    // DETECT is a macro defined in
    // "graphics.h" header file
    int gd = DETECT, gm, color;
  
    // initgraph initializes the
    // graphics system by loading a
    // graphics driver from disk
    initgraph(&gd, &gm, "");
  
    // Draws circle in white color
    // center at (100, 100) and radius
    // as 50
    circle(100, 100, 50);
  
    // setcolor function
    setcolor(GREEN);
  
    // Draws circle in green color
    // center at (200, 200) and radius
    // as 50
    circle(200, 200, 50);
  
    getch();
  
    // closegraph function closes the
    // graphics mode and deallocates
    // all memory allocated by
    // graphics system .
    closegraph();
  
    return 0;
}

输出 :

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。