实验二C语言图形基础知识Word文档格式.docx

上传人:b****5 文档编号:19848966 上传时间:2023-01-10 格式:DOCX 页数:12 大小:54.43KB
下载 相关 举报
实验二C语言图形基础知识Word文档格式.docx_第1页
第1页 / 共12页
实验二C语言图形基础知识Word文档格式.docx_第2页
第2页 / 共12页
实验二C语言图形基础知识Word文档格式.docx_第3页
第3页 / 共12页
实验二C语言图形基础知识Word文档格式.docx_第4页
第4页 / 共12页
实验二C语言图形基础知识Word文档格式.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

实验二C语言图形基础知识Word文档格式.docx

《实验二C语言图形基础知识Word文档格式.docx》由会员分享,可在线阅读,更多相关《实验二C语言图形基础知识Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。

实验二C语言图形基础知识Word文档格式.docx

2)voidfarline(intx0,inty0,intx1,inty1);

画一条从点(x0,y0)到(x1,y1)的直线。

3)voidfarlineto(intx,inty);

画一作从现行游标到点(x,y)的直线。

4)voidfarlinerel(intdx,intdy);

画一条从现行游标(x,y)到按相对增量确定的点(x+dx,y+dy)的直线。

5)voidfarcircle(intx,inty,intradius);

以(x,y)为圆心,radius为半径,画一个圆。

6)voidfararc(intx,inty,intstangle,intendangle,intradius);

以(x,y)为圆心,radius为半径,从stangle开始到endangle结束(用度表示)画一段圆弧线。

7)voidellipse(intx,inty,intstangle,intendangle,intxradius,intyradius);

以(x,y)为中心,xradius,yradius为x轴和y轴半径,从角stangle开始到endangle结束画一段椭圆线,当stangle=0,endangle=360时,画出一个完整的椭圆。

8)voidfarrectangle(intx1,inty1,intx2,inty2);

以(x1,y1)为左上角,(x2,y2)为右下角画一个矩形框。

9)voidfardrawpoly(intnumpoints,intfar*polypoints);

画一个顶点数为numpoints,各顶点坐标由polypoints给出的多边形。

图形函数的基本表示、含义以及基本应用。

如:

1)void 

far 

clearviewport 

( 

void 

);

清除现行图形窗口的内容。

 

2)void 

outtext 

char 

*textstring 

该函数输出字符串指针textstring所指的文本在现行位置。

3.初步认识C语言图形函数的编程与运行;

在C语言环境下,运行图形程序示例,观察显示结果,分析程序结构和含义,学习C语言图形函数的编程应用;

4.修改相关程序内容,观察运行结果,总结经验和结论分析。

1)没有修改的原程序一:

#include<

graphics.h>

stdlib.h>

stdio.h>

conio.h>

intmain(void)

{

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intleft,top,right,bottom;

/*initializegraphicsandlocalvariables*/

initgraph(&

gdriver,&

gmode,"

"

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!

=grOk)/*anerroroccurred*/

{

printf("

Graphicserror:

%s\n"

grapherrormsg(errorcode));

Pressanykeytohalt:

getch();

exit

(1);

/*terminatewithanerrorcode*/

}

left=getmaxx()/2-50;

top=getmaxy()/2-50;

right=getmaxx()/2+50;

bottom=getmaxy()/2+50;

/*drawarectangle*/

rectangle(left,top,right,bottom);

/*cleanup*/

closegraph();

return0;

}

运行出来的图形:

修改后的程序一:

left=getmaxx()/2-100;

top=getmaxy()/2-100;

right=getmaxx()/2+100;

bottom=getmaxy()/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)没有修改的原程序二:

inti,maxx,maxy;

/*ourpolygonarray*/

intpoly[8];

/*initializegraphics,localvariables*/

=grOk)

/*anerroroccurred*/

grapherrormsg(errorcode));

maxx=getmaxx();

maxy=getmaxy();

poly[0]=20;

/*1stvertext*/

poly[1]=maxy/2;

poly[2]=maxx-20;

/*2nd*/

poly[3]=20;

poly[4]=maxx-50;

/*3rd*/

poly[5]=maxy-20;

/*4thvertex.fillpolyautomaticallyclosesthepolygon.*/

poly[6]=maxx/2;

poly[7]=maxy/2;

/*loopthroughthefillpatterns*/

for(i=EMPTY_FILL;

i<

USER_FILL;

i++)

/*setfillpattern*/

setfillstyle(i,getmaxcolor());

/*drawafilledpolygon*/

fillpoly(4,poly);

未修改的程序运行的图:

修改后的程序二:

intmaxx,maxy;

intpoly[10];

/*initializegraphicsandlocalvariables*/

\

/*terminatewithanerrorcode*/

setbkcolor(5);

setcolor(11);

poly[0]=10;

poly[2]=maxx-10;

poly[3]=10;

poly[4]=maxx-30;

poly[5]=maxy-10;

/*4th*/

/*drawpolydoesn'

tautomaticallyclosethepolygon,sowecloseit.*/

poly[8]=poly[0];

poly[9]=poly[1];

/*drawthepolygon*/

drawpoly(5,poly);

修改后的程序二运行的图:

intpoly[8];

修改成intpoly[10];

修改了图形的作图颜色

增加了setbkcolor(5):

修改了图形的背景颜色

修改三:

poly[1]=maxy/2:

poly[4]=maxx-50;

修改成:

poly[0]=10;

poly[2]=maxx-10;

poly[4]=maxx-30;

改变了图形的坐标位置,从而改变了图形的形状。

3)没有修改的原程序三:

intmidx,midy;

intstangle=0,endangle=360;

intxradius=100,yradius=50;

midx=getmaxx()/2;

midy=getmaxy()/2;

setcolor(getmaxcolor());

/*drawellipse*/

ellipse(midx,midy,stangle,endangle,xradius,yradius);

没有修改的原程序三运行的图:

修改后的程序三:

intxradius=100,yradius=150;

midy=getmaxy()/3;

setcolor(14);

修改后的程序三运行的图:

yradius=50;

yradius=150;

改变了椭圆的高

midy=getmaxy()/2;

midy=getmaxy()/3;

改变了顶点的位置

增加setcolor(14);

setbkcolor(5);

设置了背景颜色和图形颜色

四、上机实验报告

根据实验内容,在计算机上操作和观察、学习,并围绕上述内容写出实验结论及观察报告,写出相应的运行程序实例和运行结果,以及修改内容和相应运行结果的变化,分析其结论原因。

(不少于3个有代表性程序及运行、修改的结论)。

实验结论:

通过一些画点函数、画线函数、更换背景色、作图色函数,通过用之前学习的C语言,将各种函数连接起来,完成自己想要的图形,自己想要的颜色,通过更改一个数值,能让其变得“面目全非”,通过此次的编程实验能然自己的C语言图形编程能力有了明显的提高,也让自己对C语言和图形相结合有了相当的经验。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1