c语言中图形驱动程序功能_C / C ++中的图形:一些更有趣的功能

c语言中图形驱动程序功能

In this Advance Learning Tutorial of C / C ++ today, we are going to tell you about some of the functions that can be used to make the program more attractive. This works on both text and graphics modes. That is why knowing these functions before starting the graphics programming is important and also useful.

在今天的C / C ++高级学习教程中,我们将向您介绍一些可用于使程序更具吸引力的功能。 这适用于文本和图形模式。 这就是为什么在开始图形编程之前了解这些功能很重要而且很有用的原因。

1)闪烁 (1) BLINK)

We will talk about an interesting character. You must have heard about the word 'BLINKING'. If you also want to blink any character on your screen, it is possible in C / C++ as well.

我们将讨论一个有趣的角色。 您必须听说过“闪烁”一词。 如果您还想让屏幕上的任何字符闪烁,那么在C / C ++中也可以。

A constant word 'BLINK' is defined in C / C ++. With the help of which you can blink any character on the screen. The value of BLINK constant is 128. Here is given an example which shows the usage of 'BLINK'.

在C / C ++中定义了常量字“ BLINK”。 借助它,您可以使屏幕上的任何字符闪烁。 BLINK常数的值为128。这里给出一个示例,说明“ BLINK”的用法。

    textcolor( BLUE + BLINK );
    OR
    textcolor( Blue + 128 );  

Keep in mind that the BLINK character is used only with textcolor and textbackground functions on TEXT MODE. So writing only BLINK will not make any difference. You can also write value 128 at the place of BLINK. This works in both ways.

请记住,BLINK字符仅与TEXT MODE上的textcolor和textbackground函数一起使用。 因此,仅编写BLINK不会有任何区别。 您也可以在BLINK处写入值128。 这在两种方式下都有效。

See the program below and try it out...

请参阅下面的程序并尝试...

#include <conio.h> 

void main() {
	clrscr();
	 
	textcolor(BLUE + BLINK );
	 
	cprintf("Welcome to the Tutorial of Graphics\n");
	 
	getch(); 
}

After running this program you will see the ' Welcome In Advance Learning Tutorial' line in the output.

运行该程序后,您将在输出中看到“欢迎高级学习教程”行。

2)GOTOXY (2) GOTOXY)

Now let's talk about a function with which you can move the cursor to any position on the screen. It is better to understand this function properly as it is useful for creating a program in graphics. The name of this function is gotoxy. Its declaration is given below,

现在让我们讨论一个函数,通过该函数可以将光标移动到屏幕上的任何位置。 最好正确理解此功能,因为它对于在图形中创建程序很有用。 该函数的名称是gotoxy。 其声明如下:

    void gotoxy(int x , int y); 

This function takes two parameters x, y whatever value you give in x and y, the function will take the cursor to that position. Keep in mind that if you pass an invalid coordinate, then using this function will not make any sense because the compiler will ignore it.

无论您在x和y中输入的值是多少,该函数都会使用两个参数x,y,该函数会将光标移到该位置。 请记住,如果传递无效的坐标,则使用此函数没有任何意义,因为编译器将忽略它。

See the example below to see how to use the function:

请参见下面的示例,以了解如何使用该函数:

Note: Do not forget to include Header File <conio.h> before using this function.

注意:在使用此功能之前, 不要忘记包含头文件<conio.h>。

#include <conio.h> 
#include <stdio.h>
 
void main() {
	 
	clrscr();
	 
	gotoxy(20,12);
	 
	printf("Welcome to the Tutorial of Graphics\n");
	 
	getch(); 
}

Keep in mind that in this example we use printf function instead of cprintf. This is why stdio.h header file has been used. gotoxy works with both printf and cprintf.

请记住,在此示例中,我们使用printf函数而不是cprintf。 这就是为什么使用stdio.h头文件的原因。 gotoxy可与printf和cprintf一起使用。

3)延迟 (3) DELAY)

Now we will be telling you about another important function, which delay(), with the help of which you can suspend the execution of the program for some time. You must be wondering how long will the execution of the program be suspended?

现在,我们将告诉您另一个重要的函数,delay(),借助它您可以暂停程序的执行一段时间。 您一定想知道程序的执行将被暂停多长时间?

Well, it depends on the value passed in the parameter of this function. Delay function takes value in the millisecond. That is, if you want to suspend the program for 5 seconds then the function call will be as follows:

好吧,这取决于在此函数的参数中传递的值。 延迟功能的值以毫秒为单位。 也就是说,如果您要暂停程序5秒钟,则函数调用将如下所示:

    delay (5000); 

After writing this line, if any line is written below, it will be executed after 5 seconds because the execution of the program will be suspended for 5 seconds.

写入此行后,如果在下面写入任何行,则将在5秒钟后执行,因为该程序的执行将被暂停5秒钟。

Note: You must include the header file (DOS.H) before using the function. For example, see the program given below.

注意:使用该函数之前,必须包括头文件(DOS.H)。 例如,请参见下面给出的程序。

#include <conio.h> 
#include <stdio.h>
#include <dos.h>
 
void main() {
 
	clrscr();
	 
	printf("Welcome\n");
	 
	delay(5000);
	 
	printf("You are learning Graphics in C/C++\n");
	 
	getch(); 
}

After running the program, first, you will see Welcome in the output, after 5 seconds, the next line will be You are learning Graphics in C/C++.

运行该程序之后,首先,您将在输出中看到Welcome,5秒后,下一行将是You are learning学习C / C ++。

If you have any problems understanding the basic topics of C/C ++ such as printf, header file and function etc, then you can read these basic topics from our website too.

如果您在理解C / C ++的基本主题(例如printf,头文件和函数等)时遇到任何问题,那么您也可以从我们的网站上阅读这些基本主题。

That's all for today in Advance Learning Tutorial. If you have any problem in any of the topics mentioned above, then you can ask your questions in the comments section below.

今天就在高级学习教程中。 如果您对上述主题有任何疑问,可以在下面的评论部分中提问。

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

c语言中图形驱动程序功能

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值