graphics.h的功能
2021-07-07 11:58:10
深夜i
--
--
g
r
a
p
h
i
c
s
.
h
的
功
能
使用 graphics.h 函数或 WinBGIM (Windows 7) 的 C 图形可用于绘制不同的形状、以不同的字体显示文本、更改颜色等等。 使用 Turbo C 编译器中的 graphics.h 函数,您可以制作图形程序、动画、项目和游戏。 您可以绘制圆形、线条、矩形、条形和许多其他几何图形。 您可以使用可用功能更改它们的颜色并填充它们。 以下是 graphics.h 头文件的功能列表。 每个函数都讨论了它需要的参数、它的描述、使用该函数时可能出现的错误以及一个示例 C 图形程序及其输出。
C图形
C图形示例
1.绘制同心圆
#include <graphics.h>
int main()
{
int gd = DETECT, gm;
int x = 320, y = 240, radius;
initgraph(&gd, &gm, "C:\\TC\\BGI");
for ( radius = 25; radius <= 125 ; radius = radius + 20)
circle(x, y, radius);
getch();
closegraph();
return 0;
}
2.C图形程序移动小车
#include <graphics.h>
#include <dos.h>
int main()
{
int i, j = 0, gd = DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(25,240,"Press any key to view the moving car");
getch();
for( i = 0 ; i <= 420 ; i = i + 10, j++ )
{
rectangle(50+i,275,150+i,400);
rectangle(150+i,350,200+i,400);
circle(75+i,410,10);
circle(175+i,410,10);
setcolor(j);
delay(100);
if( i == 420 )
break;
if ( j == 15 )
j = 2;
cleardevice(); // clear screen
}
getch();
closegraph();
return 0;
}
C图形函数
- arc
- bar
- bar3d
- circle
- cleardevice
- closegraph
- drawpoly
- ellipse
- fillellipse
- fillpoly
- floodfill
- getarccords
- getbkcolor
- getcolor
- getdrivername
- getimage
- getmaxcolor
- getmaxx
- getmaxy
- getpixel
- getx
- gety
- graphdefaults
- grapherrormsg
- imagesize
- line
- lineto
- linerel
- moveto
- moverel
- outtext
- outtextxy
- pieslice
- putimage
- putpixel
- rectangle
- sector
- setbkcolor
- setcolor
- setfillstyle
- setlinestyle
- settextstyle
- setviewport
- textheight
- textwidth
C图形程序
- Draw shapes
- Bar chart
- Pie chart
- 3d bar chart
- Smiling face animation
- captcha
- Circles in circles
- Countdown
- Paint program in C
- Press me button game
- Web browser program
- Traffic light simulation
- Mouse pointer restricted in circle
Windows 7 或 Vista 中的图形
除了绘制 3d 条形的 bar3d 之外,大多数函数都是二维的,您也可以使用现有算法来实现这些函数。 您也可以在 C++ 程序中使用这些函数。 您可以使用这些函数在 Windows 7 和 Vista 中使用 Dev C++ 编译器开发程序。 为此,您需要下载一个额外的软件包 WinBGIm,下载 WinBGIm。 现在打开 Dev C++ 编译器去工具->包管理器,使用安装按钮,然后浏览包位置。 现在创建一个新项目并选择 WinBGIm。 该库还提供了许多可用于图像处理的功能,您可以打开图像文件、创建位图和打印图像、RGB 颜色和鼠标处理。
上一篇:
idea打包java可执行jar包
下一篇:
c中的圆函数
评论区