📄 graphic.part3.h
字号:
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
clrscr();
printf("You have %s video display card.",dname[gdriver]);
printf("Press any key to halt:");
getch();
return 0;
}
@函数名称: drawpoly
函数原型: void far drawpoly(int numpoint, int far *points)
函数功能: 画多边形
函数返回:
参数说明: numpoint-多边形点数,points-保存多边形顶点坐标的数组(x1,y1,x2,y2顺序)
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int maxx,maxy;
int poly[10];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx=getmaxx();
maxy=getmaxy();
poly[0]=20;
poly[1]=maxy/2;
poly[2]=maxx-20;
poly[3]=20;
poly[4]=maxx-50;
poly[5]=maxy-20;
poly[6]=maxx/2;
poly[7]=maxy/2;
poly[8]=poly[0];
poly[9]=poly[1];
drawpoly(5,poly);
getch();
closegraph();
return 0;
}
@函数名称: fillpoly
函数原型: void far fillpoly(int numpoints, int far *points)
函数功能: 按当前设置的填充模式和颜色填充多边形
函数返回:
参数说明: numpoints-多边形点数,points-多边形坐标数组
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int i,maxx,maxy;
int poly[8];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx=getmaxx();
maxy=getmaxy();
poly[0]=20;
poly[1]=maxy/2;
poly[2]=maxx-20;
poly[3]=20;
poly[4]=maxx-50;
poly[5]=maxy-20;
poly[6]=maxx/2;
poly[7]=maxy/2;
for (i=EMPTY_FILL;i<USER_FILL;i++)
{
setfillstyle(i,getmaxcolor());
fillpoly(4,poly);
getch();
}
closegraph();
return 0;
}
@函数名称: floodfill
函数原型: void far floodfill(int x, int y, int border)
函数功能: 填充一个有边界的区域
函数返回:
参数说明: x,y-要填充区域内的任意一点坐标,border-填充区域边界的颜色.
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int maxx,maxy;
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx=getmaxx();
maxy=getmaxy();
setcolor(getmaxcolor());
setfillstyle(SOLID_FILL,getmaxcolor());
rectangle(0,0,maxx,maxy);
circle(maxx/3,maxy /2,50);
circle(maxx/2,20,100);
circle(maxx-20,maxy-50,75);
circle(20,maxy-20,25);
getch();
floodfill(2,2,getmaxcolor());
getch();
closegraph();
return 0;
}
@函数名称: getgraphmode
函数原型: int far getgraphmode(void)
函数功能: 得到当前图形模式
函数返回: 图形模式数值,含义如下:
CGAC0=0 320x200 palette 0 1 page
CGAC1=1 320x200 palette 1 1 page
CGAC2=2 320x200 palette 2 1 pag
CGAC3=3 320x200 palette 3 1 page
CGAHI=4 640x200 1 page
MCGAC0=0 320x200 palette 0 1 page
MCGAC1=1 320x200 palette 1 1 page
MCGAC2=2 320x200 palette 2 1 page
MCGAC3=3 320x200 palette 3 1 page
MCGAMED=4 640x200 1 page
MCGAHI=5 640x480 1 page
EGALO=0 640x200 16 color 4 pages
EGAHI=1 640x350 16 color 2 pages
EGA64LO=0 640x200 16 color 1 page
EGA64HI=1 640x350 4 color 1 page
EGAMONOHI=0 640x350 64K on card 1 page 256K on card 4 pages
HERCMONOHI=0 720x348 2 pages
ATT400C0=0 320x200 palette 0 1 page
ATT400C1=1 320x200 palette 1 1 page
ATT400C2=2 320x200 palette 2 1 page
ATT400C3=3 320x200 palette 3 1 page
ATT400MED=4 640x200 1 page
ATT400HI=5 640x400 1 page
VGALO=0 640x200 16 color 4 pages
VGAMED=1 640x350 16 color 2 pages
VGAHI=2 640x480 16 color 1 page
PC3270HI=0 720x350 1 page
IBM8514LO=0 640x480 256 colors
IBM8514HI=1 1024x768 256 colors
参数说明:
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int midx,midy,mode;
char numname[80],modename[80];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx=getmaxx()/2;
midy=getmaxy()/2;
mode=getgraphmode();
sprintf(numname,"%d is the current mode number.",mode);
sprintf(modename,"%s is the current graphics mode",getmodename(mode));
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(midx,midy,numname);
outtextxy(midx,midy+2*textheight("W"),modename);
getch();
closegraph();
return 0;
}
@函数名称: setgraphmode
函数原型: void far setgraphmode(int mode)
函数功能: 设置图形工作模式
函数返回:
参数说明: 图形模式数值
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define BUFSIZE 100
int main()
{
int gdriver=DETECT,gmode,errorcode;
int x,y,oldsize;
char msg[80];
oldsize=setgraphbufsize(BUFSIZE);
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x=getmaxx()/2;
y=getmaxy()/2;
sprintf(msg,"Graphics buffer size: %d",BUFSIZE);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(x,y,msg);
sprintf(msg,"Old graphics buffer size: %d",oldsize);
outtextxy(x,y+textheight("W"),msg);
getch();
closegraph();
return 0;
}
@函数名称: getimage
函数原型: void far getimage(int left,int top,int right,int bottom,void far *bitmap)
函数功能: 保存矩形图形屏幕的内容到bitmap缓冲区
函数返回:
参数说明: Left,Top,Right,bottom-矩形屏幕坐标
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
void save_screen(void far *buf[4]);
void restore_screen(void far *buf[4]);
int maxx,maxy;
int main()
{
int gdriver=DETECT,gmode,errorcode;
void far *ptr[4];
/* auto-detect the graphics driver and mode */
initgraph(&gdriver,&gmode,"");
errorcode=graphresult(); /* check for any errors */
if(errorcode!=grOk)
{
printf("Graphics error: %s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx=getmaxx();
maxy=getmaxy();
/* draw an image on the screen */
rectangle(0,0,maxx,maxy);
line(0,0,maxx,maxy);
line(0,maxy,maxx,0);
save_screen(ptr); /* save the current screen */
getch(); /* pause screen */
cleardevice(); /* clear screen */
restore_screen(ptr); /* restore the screen */
getch(); /* pause screen */
closegraph();
return 0;
}
void save_screen(void far *buf[4])
{
unsigned size;
int ystart=0,yend,yincr,block;
yincr=(maxy+1)/4;
yend=yincr;
size=imagesize(0,ystart,maxx,yend);
for (block=0;block<=3;block++)
{
if((buf[block]=farmalloc(size))==NULL)
{
closegraph();
printf("Error: not enough heap space in save_screen().\n");
exit(1);
}
getimage(0,ystart,maxx,yend,buf[block]);
ystart=yend+1;
yend+=yincr+1;
}
}
void restore_screen(void far *buf[4])
{
int ystart=0,yend,yincr,block;
yincr=(maxy+1)/4;
yend=yincr;
for(block=0;block<=3;block++)
{
putimage(0,ystart,buf[block],COPY_PUT);
farfree(buf[block]);
ystart=yend+1;
yend+=yincr+1;
}
}
@函数名称: putimage
函数原型: void far putimage(int left, int top, void far *bitmap, int op)
函数功能: 将先前存储的屏幕图象恢复到屏幕上
函数返回:
参数说明: left,top-恢复的位置,bitmap-存储的图象位图缓存
top 恢复模式,取值为以下5个数值:
COPY_PUT 完全拷贝
XOR_PUT 与现在的屏幕图象异或拷贝
OR_PUT 与现在的屏幕图象相或拷贝
AND_PUT 与现在的屏幕图象相与拷贝
NOT_PUT 取反拷贝到屏幕上
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define ARROW_SIZE 10
void draw_arrow(int x,int y);
int main()
{
int gdriver=DETECT,gmode,errorcode;
void *arrow;
int x,y,maxx;
unsigned int size;
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx=getmaxx();
x=0;
y=getmaxy()/2;
draw_arrow(x,y);
size=imagesize(x,y-ARROW_SIZE,x+(4*ARROW_SIZE),y+ARROW_SIZE);
arrow=malloc(size);
getimage(x,y-ARROW_SIZE,x+(4*ARROW_SIZE),y+ARROW_SIZE,arrow);
while (!kbhit())
{
putimage(x,y-ARROW_SIZE,arrow,XOR_PUT);
x +=ARROW_SIZE;
if (x>=maxx)x=0;
putimage(x,y-ARROW_SIZE,arrow,XOR_PUT);
}
free(arrow);
closegraph();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -