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語言中圖形驅動程序功能