实验二c语言图形基础知识
一、 实验目的
认识c语言程序中的图形参数和有关图形显示的基础知识;
学习C语言各种图形函数和图形命令及其使用。
学习并运行图形显示例程,掌握C语言图形编程基本常识。
二、 实验设备及软件
计算机系统 ft = getmaxx() / 2-50;
top 二 getmaxy() / 2-50;
right = getmaxx() / 2 + 50;
bottom = getmaxy() / 2 +50;
/* draw a rectangle */
rectangle(left, top, right, bottom);
/* clean up */
getchO ;
closegraph ();
return 0;
运行出来的图形:
修改后的程序一:
^include <graphics. h>
ttinclude <stdlib. h>
^include <stdio. h>
ttinclude <conio. h>
int main(void)
(
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int left, top, right, bottom;
/* initialize graphics and local variables */ initgraph(fegdriver, &gmode, 〃〃);
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf(^Graphics error: %s\n〃, grapherrormsg(errorcode));
printf (z/Press any key to halt:〃);
getchO ;
exit (1); /* terminate with an error code */
}
left = getmaxx() / 2 - 100;
top = getmaxy() / 2 - 100;
right = getmaxx() / 2 + 100;
bottom = getmaxy() / 2 + 100;
setbkcolor (1);
setcolor (7);
/* draw a rectangle */
rectangle(left, top, right, bottom);
/* clean up */
getch();
closegraph ();
return 0;
)
修改后的程序一运行的图形:
修改一:left = getmaxxO / 2 - 50; top = getmaxy () / 2 - 50;right = getmaxx () / 2 + 50;bottom = getmaxy() / 2 + 50;修改参数克改变举行的四个定点的 位置,从而改变大小
修改二:增加setbkcolor (1) ; setcolor (7);改变了图形的颜色和背景颜色
2)没有修改的原程序二: #include <graphics. h>
ttinclude <stdlib. h> ftinclude <stdio. h>
^include <conio. h> int main(void)
(
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int i, maxx, maxy;
/* our polygon array */
int poly[8];
/* initialize graphics, local variables */
initgraph(fegdriver, &gmode, 〃〃);
/* read result of initialization */
errorcode 二 graphresult();
if (errorcode != grOk)
/* an error occurred */
(
printf(^Graphics error: %s\n〃,
grapherrorms g(errorcode));
printf(z/Press any key to halt:");
getchO ;
exit (1);
/* terminate with an error code */
实验二:C语言图形基础知识 来自淘豆网m.daumloan.com转载请标明出处.