graphics.h头文件

C中的颜色说明 (Color Description in C)

setbkcolor sets the background to the color specified by the color or the number. The argument color may be a name or a number as given in the table below. (These symbolic names are defined in graphics.h). These colors can also be used to set textcolor (color of the text) or filling inside various shapes that you make in your program. We shall first learn about the color and their values and then we will learn it via the programs.

setbkcolor将背景设置为由颜色或数字指定的颜色。 参数color可以是下表中给出的名称或数字。 (这些符号名称在graphics.h中定义)。 这些颜色还可用于设置textcolor (文本的颜色)或填充您在程序中制作的各种形状。 我们将首先了解颜色及其值,然后通过程序进行学习。

Color                Numeric 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

C语言中的示例图形程序 (Sample Graphics programs in C)

1. Background color

1.背景色

#include<graphics.h> /* header file */
#include<conio.h>
main()
{/* the following two lines are the syntax for writing a particular
program in graphics. It's explanation is given after the program.*/
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setbkcolor (GREEN);
getch();
closegraph();
return 0;
}

Output

输出量

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

什么是initgraph,gd和gm? (What are initgraph, gd and gm?)

  • gd = graphdriver;

    gd = graphdriver;

  • gm = graphmode;

    gm = graphmode;

Syntax for initgraph:

initgraph的语法:

    void initgraph (int *graphdriver, int *graphmode, char *pathtodriver) ;

Description for initgraph:

初始化图说明:

initgraph

初始化图

initgraph is used to initialize the graphics system by loading a graphics driver from disk and thereby putting the system into graphics mode.

initgraph用于通过从磁盘加载图形驱动程序并由此使系统进入图形模式来初始化图形系统。

To start the graphics system, we first call the initgraph function. initgraph may use a particular graphics driver and mode, or it may auto-detect and pick the corresponding driver at runtime, according to our needs.

要启动图形系统,我们首先调用initgraph函数。 根据我们的需要, initgraph可以使用特定的图形驱动程序和模式,也可以在运行时自动检测并选择相应的驱动程序。

If we tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode. It also resets all graphics settings to their defaults values like current position, color, viewport and so on and also resets graphresult to 0.

如果我们告诉initgraph自动检测,它将调用detectgraph选择图形驱动程序和模式。 它还会将所有图形设置重置为其默认值,例如当前位置,颜色,视口等,并将graphresult重置为0。

Normally, memory is allocated by initgraph to load a particular graphics driver through _graphgetmem, then it loads the appropriate BGI file from disk.

通常,内存是由initgraph分配的,以通过_graphgetmem加载特定的图形驱动程序,然后从磁盘加载适当的BGI文件。

pathtodriver

路径驱动程序

pathtodriver denotes the directory path where initgraph must look for graphic drivers. initgraph first goes through the directed path to look for the files and if they are not found there, it goes to the current directory. The graphic driver must files must be present in the current directory if the pathtodriver is null.

pathtodriver表示initgraph必须在其中查找图形驱动程序的目录路径。 initgraph首先通过定向路径查找文件,如果在该文件中找不到文件,它将转到当前目录。 如果pathtodriver为null,则图形驱动程序必须在当前目录中存在文件。

graphdriver

图形驱动程序

*graphdriver is the integer that specifies which graphics driver is to be used. We can give it a value using a constant of the graphics_drivers enum type, which is defined in graphics.h and listed below.

* graphdriver是整数,它指定要使用的图形驱动程序。 我们可以给它使用graphics_drivers枚举类型,其在graphics.h中定义并在下面列出的恒定的值。

graphics_drivers constant       Numeric value
DETECT                          0 (requests autodetect)
CGA                         1
MCGA                            2
EGA                         3
EGA64                           4
EGAMONO                         5
IBM8514                         6
HERCMONO                    7
ATT400                          8
VGA                         9
PC3270                          10

graphmode

图形模式

*graphmode is also an integer that specifies the initial graphics mode. The table for the values of *graphmode are given in the tlink below and its values are assigned in the same way as for *graphdriver.

* graphmode也是指定初始图形模式的整数。 * graphmode的值表在下面的链接中给出,其值的分配方式与* graphdriver相同。

graphdriver and graphmode must be given proper values from the tables or we will get absurd and unexpected results. The exception here is when graphdriver = DETECT. In this case, initgraph sets *graphmode to the highest resolution available for the detected driver.

必须从表中给graphdriver和graphmode适当的值,否则我们将得到荒谬和意外的结果。 例外是graphdriver = DETECT。 在这种情况下,initgraph将* graphmode设置为可用于检测到的驱动程序的最高分辨率。

Reference: https://www.cs.colorado.edu/~main/bgi/doc/initgraph.html

参考 :https://www.cs.colorado.edu/~main/bgi/doc/initgraph.html

什么是华大基因? (What is BGI?)

Borland Graphics Interface (BGI) is a graphics library that is bundled with several Borland compilers for the DOS operating systems since 1987. The library loads graphic drivers (*.BGI) and vector fonts (*.CHR) from disk so to provide device independent graphics support to the programmers.

自1987年以来,Borland图形接口(BGI)是一个图形库,它与用于DOS操作系统的若干Borland编译器捆绑在一起 。 该库从磁盘加载图形驱动程序(* .BGI)和矢量字体(* .CHR),以便为程序员提供独立于设备的图形支持。

BGI is accessible in C/C++ with graphics.lib/graphics.h.

在C / C ++中,可以通过graphics.lib / graphics.h访问BGI。

Reference: Borland Graphics Interface

参考: Borland图形界面

什么是closegraph()? (What is closegraph()?)

Syntax for closegraph() :

closegraph()的语法:

void closegraph (int wid= ALL_WINDOWS);

Description:

描述:

closegraph deallocates the memory allocated by the graphics system and then restores the screen to the mode it was in before calling initgraph.

closegraph取消分配图形系统分配的内存,然后将屏幕恢复为调用initgraph之前的模式。

Return Value: Return value is none.

返回值:返回值为无。

Windows Version of closegraph() :

Windows版本的closegraph():

In windows version of closegraph, there is an optional parameter called the ‘wid’ which is the window id (returned by initwindow) of the window that is supposed to be closed.

在Windows版本的closegraph中,有一个可选参数称为“ wid”,它是应该关闭的窗口的窗口ID(由initwindow返回)。

The wid parameter can also take one of the two constant values given below:

wid参数还可以采用下面给出的两个常数值之一:

  1. CURRENT_WINDOW which closes only the current window or

    CURRENT_WINDOW仅关闭当前窗口或

  2. ALL_WINDOWS which by default closes all the open graphic windows.

    ALL_WINDOWS默认情况下会关闭所有打开的图形窗口。

By closing the current window, current window will no longer exist and we will not be able to give any further drawing commands until a new window is created or a current window is set by calling setcurrentwindow.

通过关闭当前窗口,当前窗口将不再存在,并且在创建新窗口或通过调用setcurrentwindow设置当前窗口之前,我们将无法提供任何其他绘制命令。

Reference: https://www.cs.colorado.edu/~main/bgi/doc/closegraph.html

参考: https : //www.cs.colorado.edu/~main/bgi/doc/closegraph.html

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

2. Text color

2.文字颜色

#include<stdio.h>
#include<conio.h>
int main()
{textcolor(RED);
clrcsr();
cprintf("HELLO WORLD\N");
getch();
return 0;
}

Output

输出量

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

3. Circle Graphics

3.圆形图形

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{int gd=DETECT, gm; int i;
initgraph (&gd,&gm,"c:\tc\\bgi");
clrscr();
for(i=0;i<500;i++)
{setcolor(i);
//coordinates of center from x axis, y axis, radius
circle(100,100,30+i);
delay(30);
//cleardevice(); //try with and without cleardevice();
}
getch();
closegraph();
}

Output

输出量

The circles will keep on growing till the assigned number.

圈子将继续增长,直到分配的数字为止。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

4. Hut Graphics

4.小屋图形

#include<graphics.h>
#include<conio.h>
int main(){int gd = DETECT,gm;
initgraph(&gd, &gm, "X:\\TC\\BGI");
/* Draw Hut */
setcolor(WHITE);
rectangle(150,180,250,300);
rectangle(250,180,420,300);
rectangle(180,250,220,300);
line(200,100,150,180);
line(200,100,250,180);
line(200,100,370,100);
line(370,100,420,180);
/* Fill colours */
setfillstyle(SOLID_FILL, BROWN);
floodfill(152, 182, WHITE);
floodfill(252, 182, WHITE);
setfillstyle(SLASH_FILL, BLUE);
floodfill(182, 252, WHITE);
setfillstyle(HATCH_FILL, GREEN);
floodfill(200, 105, WHITE);
floodfill(210, 105, WHITE);
getch();
closegraph();
return 0;
}

Output

输出量

Author’s Note:

作者注:

These programs are made and tested in TURBO C7. This is my request to all the readers to please run the program for better understanding of the code. I’m always there to help in case of any query. Happy Coding!

这些程序是在TURBO C7中制作和测试的。 这是我对所有读者的要求,请运行程序以更好地理解代码。 如有任何查询,我随时都会为您提供帮助。 编码愉快!

翻译自: https://www.includehelp.com/c/graphics-functions-examples.aspx

graphics.h头文件

graphics.h头文件_C语言图形(graphics.h头文件功能和示例)相关推荐

  1. c语言编程基础课件,第7章_C语言图形编程基础课件

    第7章_C语言图形编程基础课件 狭义的组织变革是指组织根据外部环境的变化和内部情况的变化及时地改变自己的内在组织结构,以适应客观发展的需要. 狭义的组织变革是指组织根据外部环境的变化和内部情况的变化及 ...

  2. 单片机sleep函数的头文件_c语言的 sleep函数到底在哪个头文件里啊

    展开全部 在里面. 在VC中使用时,sleep函数的头文件为windows.h,在Linux下,gcc编译器中,使用的头文件因gcc版本62616964757a686964616fe59b9ee7ad ...

  3. c语言头文件和源文件_C语言头文件防卫式声明

    C语言一般提供三种预处理功能:宏处理.文件包含.条件编译.头文件防卫式申明中会用到条件编译中 #ifndef.#define.#endif 的用法.所以,首先价绍下条件编译. 1 条件编译 一般情况下 ...

  4. c语言getchar在哪个头文件_c语言入门(一)

    知识点1[写代码的过程] 编辑器:程序员写代码的过程(记事本.vc6.0.vim)(让程序员看懂) 编译器:查看代码的语法错误,生成汇编语言. 汇编器:将生成好汇编语言 生成 二进制语言(目标文件) ...

  5. c语言头文件_C语言学习之头文件的原理和使用方法

    头文件是扩展名为 .h 的文件,包含了 C 函数声明和宏定义,被多个源文件中引用共享.有两种类型的头文件:程序员编写的头文件和编译器自带的头文件. 在程序中要使用头文件,需要使用 C 预处理指令 #i ...

  6. c 包含其他文件_C语言:全局变量在多个c文件中公用的方法!

    用C语言编写程序的时候,我们经常会遇到这样一种情况:希望在头文件中定义一个全局变量,然后包含到两个不同的c文件中,希望这个全局变量能在两个文件中共用. 举例说明:项目文件夹project下有main. ...

  7. c malloc 头文件_c++个人学习笔记——1.头文件声明

    简单介绍了C++头文件声明与C语言的差异,并对常见的部分头文件作了介绍. //C++中常用写法 最简单的C++程序往往是上面这样声明头文件. #include为C/C++中包含头文件命令,用于将指定头 ...

  8. C语言semaphore头文件,C语言再学习 -- 常用头文件和函数

    Linux常用头文件如下: POSIX标准定义的头文件 < dirent.h>        目录项 < fcntl.h>         文件控制 < fnmatch. ...

  9. java定义异常的头文件_c++ 声明定义都在头文件中怎么include?

    瀉藥, @李毅 老大已經點名你出錯的地方了, @felix 老大也指出是ODR的問題, 看來窩除了能在上面說下原理沒什麼做了, 哈哈. 不過既然兩位老大都沒有將原理和你的庫結合, 那麼這個微小工作就由 ...

最新文章

  1. 热点推荐:秒杀系统架构分析与实战--转载
  2. 智能技术可以帮助解决人口老龄化问题吗?
  3. discord linux_最好的Discord机器人来启动服务器
  4. html怎么用小小的图片铺满作为背景,多种背景图片随机切换的应用
  5. php连接postgresql数据库
  6. (转载)web.xml中 IntrospectorCleanupListener的作用
  7. 双闭环可逆直流脉宽pwm调速系统设计及matlab仿真验证_,双闭环可逆直流脉宽PWM调速系统的设计最终版(手机版)...
  8. Linux与windows常用软件大比拼
  9. yolov5 数据集预处理(多文件夹同时提取文件并分类)(同时随机提取一定比例的图片和txt文件到指定文件)
  10. 你写论文时发现了哪些神网站?
  11. 相机视场角和焦距_镜头焦距和视场角介绍!
  12. 武汉java软谋教育坑吗_软谋在线教育诚招php,java,.net,设计师讲师(可兼职)...
  13. 运维数据防泄露解决方案
  14. wi-fi频宽设置_如何设置TP-Link Wi-Fi智能插头
  15. 悟空CRM项目测试实战(4)
  16. 问题 C: 零基础学C/C++26——判断某整数是否既是5又是7的整数倍
  17. Hive体系结构介绍
  18. SAP上线时未清采购订单处理
  19. 2017年英语四级作文
  20. unity绘制管道_在Unity里写一个纯手动的渲染管线(一)

热门文章

  1. linux的无值守安装实例
  2. 由终端设备连接到信息插座的连线组成,用于连接终端设备与IO/Base的是什么呢?
  3. 市面上的长距离激光测距仪的小知识?TFN LR20KI带你走近长距离激光测距的世界。
  4. [深度学习][原创]使用labelImg+yolov5完成所有slowfast时空动作检测项目-训练测试篇
  5. openssl命令生成根证书和使用根证书签名工作证书
  6. popen和system函数的区别 以及 popen打开的FILE指针能否用close替代fclose关闭
  7. 1 - 操作系统发展史及其基础知识
  8. 《传播学史》读后感优秀范文5000字
  9. 【问题篇】免费下载使用RDM
  10. iphone13配什么蓝牙耳机最好?最适合苹果手机的蓝牙耳机推荐