求助C语言的有关图形处理的函数知识还有涉及如何与键盘鼠标建立关联的函数

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/09 05:25:49

求助C语言的有关图形处理的函数知识还有涉及如何与键盘鼠标建立关联的函数
求助C语言的有关图形处理的函数知识
还有涉及如何与键盘鼠标建立关联的函数

求助C语言的有关图形处理的函数知识还有涉及如何与键盘鼠标建立关联的函数
函数名:line
功 能:在指定两点间画一直线
用 法:void far line(int x0,int y0,int x1,int y1);
程序例:
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT,gmode,errorcode;
int xmax,ymax;
/* initialize graphics and local variables */
initgraph(&gdriver,&gmode,"");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error:%s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();
/* draw a diagonal line */
line(0,0,xmax,ymax);
/* clean up */
getch();
closegraph();
return 0;
}
函数名:linerel
功 能:从当前位置点(CP)到与CP有一给定相对距离的点画一直线
用 法:void far linerel(int dx,int dy);
程序例:
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT,gmode,errorcode;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver,&gmode,"");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error:%s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
/* move the C.P.to location (20,30) */
moveto(20,30);
/* create and output a
message at (20,30) */
sprintf(msg," (%d,%d)",getx(),gety());
outtextxy(20,30,msg);
/* draw a line to a point a relative
distance away from the current
value of C.P.*/
linerel(100,100);
/* create and output a message at C.P.*/
sprintf(msg," (%d,%d)",getx(),gety());
outtext(msg);
/* clean up */
getch();
closegraph();
return 0;
}
函数名:circle
功 能:在给定半径以(x,y)为圆心画圆
用 法:void far circle(int x,int y,int radius);
程序例:
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT,gmode,errorcode;
int midx,midy;
int radius = 100;
/* initialize graphics and local variables */
initgraph(&gdriver,&gmode,"");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error:%s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* draw the circle */
circle(midx,midy,radius);
/* clean up */
getch();
closegraph();
return 0;
}
函数名:cleardevice
功 能:清除图形屏幕
用 法:void far cleardevice(void);
程序例:
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT,gmode,errorcode;
int midx,midy;
/* initialize graphics and local variables */
initgraph(&gdriver,&gmode,"");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error:%s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* for centering screen messages */
settextjustify(CENTER_TEXT,CENTER_TEXT);
/* output a message to the screen */
outtextxy(midx,midy,"press any key to clear the screen:");
/* wait for a key */
getch();
/* clear the screen */
cleardevice();
/* output another message */
outtextxy(midx,midy,"press any key to quit:");
/* clean up */
getch();
closegraph();
return 0;
}