1、2) void far line(int x0, int y0, int x1, int y1);画一条从点(x0, y0)到(x1, y1)的直线。3) void far lineto(int x, int y);画一作从现行游标到点(x, y)的直线。4) void far linerel(int dx, int dy);画一条从现行游标(x, y)到按相对增量确定的点(x+dx, y+dy)的直线。5) void far circle(int x, int y, int radius);以(x, y)为圆心, radius为半径, 画一个圆。6) void far arc(int x,
2、int y, int stangle, int endangle, int radius);以(x, y)为圆心, radius为半径, 从stangle开始到endangle结束(用度表示)画一段圆弧线。7) void ellipse(int x, int y, int stangle, int endangle, int xradius,int yradius);以(x, y)为中心, xradius, yradius为x轴和y轴半径, 从角stangle开始到endangle结束画一段椭圆线, 当stangle=0, endangle=360时, 画出一个完整的椭圆。8) void fa
3、r rectangle(int x1, int y1, int x2, inty2);以(x1, y1)为左上角, (x2, y2)为右下角画一个矩形框。9) void far drawpoly(int numpoints, int far *polypoints);画一个顶点数为numpoints, 各顶点坐标由polypoints 给出的多边形。图形函数的基本表示、 含义以及基本应用。如:1) voidfarclearviewport(void);清除现行图形窗口的内容。2) voidouttextchar*textstring该函数输出字符串指针textstring所指的文本在现行位置。
4、3. 初步认识C语言图形函数的编程与运行; 在 C 语言环境下, 运行图形程序示例,观察显示结果,分析程序结构和含义,学习C语言图形函数的编程应用;4. 修改相关程序内容,观察运行结果,总结经验和结论分析。1) 没有修改的原程序一:#include stdlib.hstdio.hconio.hint main(void) /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int left, top, right, bottom; /* initialize graphics and local variab
5、les */ initgraph(&gdriver, &gmode, /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ printf(Graphics error: %sn, grapherrormsg(errorcode);Press any key to halt: getch(); exit(1); /* terminate with an error code */ left = getmaxx() / 2 - 50;
6、 top = getmaxy() / 2 - 50; right = getmaxx() / 2 + 50; bottom = getmaxy() / 2 + 50; /* draw a rectangle */ rectangle(left,top,right,bottom); /* clean up */ closegraph(); return 0;运行出来的图形:修改后的程序一: left = getmaxx() / 2 - 100; top = getmaxy() / 2 - 100; right = getmaxx() / 2 + 100; bottom = getmaxy() /
7、 2 + 100; setbkcolor(1); setcolor(7);修改后的程序一运行的图形:修改一:left = getmaxx() / 2 - 50;top = getmaxy() / 2 - 50;right = getmaxx() / 2 + 50;bottom = getmaxy() / 2 + 50;修改参数克改变举行的四个定点的位置,从而改变大小修改二:增加setbkcolor(1);setcolor(7);改变了图形的颜色和背景颜色2) 没有修改的原程序二: int i, maxx, maxy; /* our polygon array */ int poly8; /*
8、initialize graphics, local variables */= grOk) /* an error occurred */, grapherrormsg(errorcode); maxx = getmaxx(); maxy = getmaxy(); poly0 = 20; /* 1st vertext */ poly1 = maxy / 2; poly2 = maxx - 20; /* 2nd */ poly3 = 20; poly4 = maxx - 50; /* 3rd */ poly5 = maxy - 20; /* 4th vertex. fillpoly autom
9、atically closes the polygon. */ poly6 = maxx / 2; poly7 = maxy / 2; /* loop through the fill patterns */ for (i=EMPTY_FILL; iUSER_FILL; i+) /* set fill pattern */ setfillstyle(i, getmaxcolor(); /* draw a filled polygon */ fillpoly(4, poly);未修改的程序运行的图:修改后的程序二: int maxx, maxy; int poly10; /* initializ
10、e graphics and localvariables */, /* termina te with an error code */ setbkcolor(5); setcolor(11); poly0 = 10; poly2 = maxx - 10; poly3 = 10; poly4 = maxx - 30; poly5 = maxy - 10; /* 4th */* drawpoly doesnt automatically close the polygon, so we close it.*/ poly8 = poly0; poly9 = poly1; /* draw the
11、polygon */ drawpoly(5, poly);修改后的程序二运行的图:int poly8;修改成 int poly10;修改了图形的作图颜色增加了setbkcolor(5):修改了图形的背景颜色修改三: poly1 = maxy / 2:poly4 = maxx - 50;修改成:poly0 = 10;poly2 = maxx - 10;poly4 = maxx - 30;改变了图形的坐标位置,从而改变了图形的形状。3) 没有修改的原程序三: int midx, midy; int stangle = 0, endangle = 360; int xradius = 100, yr
12、adius = 50; midx = getmaxx() / 2; midy = getmaxy() / 2; setcolor(getmaxcolor(); /* draw ellipse */ ellipse(midx, midy, stangle, endangle, xradius, yradius);没有修改的原程序三运行的图:修改后的程序三: int xradius = 100, yradius =150; midy = getmaxy() / 3; setcolor(14);修改后的程序三运行的图:yradius = 50;yradius =150;改变了椭圆的高midy = g
13、etmaxy() / 2;midy = getmaxy() / 3;改变了顶点的位置增加setcolor(14);setbkcolor(5);设置了背景颜色和图形颜色四、上机实验报告根据实验内容,在计算机上操作和观察、学习,并围绕上述内容写出实验结论及观察报告,写出相应的运行程序实例和运行结果,以及修改内容和相应运行结果的变化,分析其结论原因。(不少于3个有代表性程序及运行、修改的结论)。实验结论:通过一些画点函数、画线函数、更换背景色、作图色函数,通过用之前学习的C语言,将各种函数连接起来,完成自己想要的图形,自己想要的颜色,通过更改一个数值,能让其变得“面目全非”,通过此次的编程实验能然自己的C语言图形编程能力有了明显的提高,也让自己对C语言和图形相结合有了相当的经验。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1