计算机图形学课程设计(共11页).doc

上传人:飞****2 文档编号:13591568 上传时间:2022-04-30 格式:DOC 页数:11 大小:25.50KB
返回 下载 相关 举报
计算机图形学课程设计(共11页).doc_第1页
第1页 / 共11页
计算机图形学课程设计(共11页).doc_第2页
第2页 / 共11页
点击查看更多>>
资源描述

《计算机图形学课程设计(共11页).doc》由会员分享,可在线阅读,更多相关《计算机图形学课程设计(共11页).doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上计算机图形学课程设计 运行环境turboc2.0 如果有疑问请发邮件到xuyuanfei本程序完成了橡皮筋直线,橡皮筋圆,橡皮筋矩形框,多边形裁剪和3阶B曲线的作图,且有比较友好的界面#ifndef _GRAPHICS_C_#define _GRAPHICS_C_#endif#define _MOUSE#define CIRCLE 1#define LINE 2#define RECTANGLE 3#include stdio.h#include string.h#includegraphics.h#includemath.hint flag,num;int x,y,

2、oldx,oldy,px,py;int a4,b4;char string120;char zuobiao20;#include union REGS inreg,outreg;struct SREGS sr;void _mytreat(int,int,int,int);void _write(char*);void mycross(int x,int y)setcolor(15);outtextxy(500,468,zuobiao);sprintf(zuobiao,x=%d,y=%d,x,y);setcolor(8);outtextxy(500,468,zuobiao);line(x-3,y

3、-3,x+3,y+3);line(x+3,y-3,x-3,y+3);void mycircle(double x,double y,double r)double i;for(i=0.0;i360.0;i=i+4)line(x+r*cos(i+1)/360*3.1415*2),y+r*sin(i+1)/360*3.1415*2),x+r*cos(i+4.0)/360*3.1415*2),y+r*sin(i+4.0)/360*3.1415*2);void _Bezer(int a3,int b3,int m)int k,n,a0,a1,a2,a3,b0,b1,b2,b3,x,y;double i

4、,t;setwritemode(0);a0=(am%4+4*am%4+1+am%4+2)/6;a1=(am%4+2-am%4)/2;a2=(am%4-2*am%4+1+am%4+2)/2;a3=-(am%4-3*am%4+1+3*am%4+2-am%4+3)/6;b0=(bm%4+4*bm%4+1+bm%4+2)/6;b1=(bm%4+2-bm%4)/2;b2=(bm%4-2*bm%4+1+bm%4+2)/2;b3=-(bm%4-3*bm%4+1+3*bm%4+2-bm%4+3)/6;for(i=0;i3;i+=0.1)t=i/3;x=a0+a1*t+a2*t*t+a3*t*t*t;y=b0+

5、b1*t+b2*t*t+b3*t*t*t;if(i=0)moveto(x,y);lineto(x,y);setwritemode(1);void DisplayMouse()inreg.x.ax=1;int86(0x33,&inreg,&outreg);void CloseMouse()inreg.x.ax=2;int86(0x33,&inreg,&outreg);union REGS DisplayMouseStatus()inreg.x.ax=3;int86(0x33,&inreg,&outreg);return outreg;void meun(int x,int y,char *str

6、)setcolor(8);outtextxy(x+5,28,str);setcolor(15);line(x,22,x,40);line(x,22,y,22);setcolor(8);line(x,40,y,40);line(y,22,y,40);void drawwindows()setbkcolor(7); /*7*/setcolor(8);rectangle(0,20,640,460);rectangle(0,0,640,20);setfillstyle(1,1);floodfill(1,1,8);rectangle(0,460,640,480);setfillstyle(1,15);f

7、loodfill(1,461,8);setcolor(RED);outtextxy(10,468,Finished By XuYuanFei.);setcolor(15);line(0,41,640,41);line(0,459,640,459);setcolor(8);line(0,42,640,42);setcolor(15);rectangle(610,3,630,17);setfillstyle(1,7);floodfill(611,4,15);setcolor(8);line(610,17,630,17);line(630,3,630,17);line(611,4,628,16);l

8、ine(611,16,628,4);rectangle(2,44,635,459);setcolor(15);rectangle(3,45,634,458);line(611,3,628,15);line(611,15,628,3);meun(5,55,line);meun(65,165,rectangle);meun(175,250,circle);meun(260,330,Bezer);meun(340,400,Cut);void GetMouseXY(int *x,int *y)DisplayMouse();outreg=DisplayMouseStatus();*x=outreg.x.

9、cx;*y=outreg.x.dx;int _cut()double a1120,b1120,a2120,b2120;int x1,y1,x2,y2,t,t1=0,t2,mark=0,w=0,i;num=0;flag=CIRCLE;while(outreg.x.bx=1)GetMouseXY(&x,&y);while(1)GetMouseXY(&x,&y);if(oldx!=x|oldy!=y)if(y43&y0)line(a1num-1,b1num-1,a1num,b1num);num+;if(mark=1)if(w=0)x1=x,y1=y;w=1;num=0;else if(w=1)x2=

10、x,y2=y;rectangle(x1,y1,x2,y2);for(i=1;ix2)t=x1;x1=x2;x2=t;if(y1y2)t=y1;y1=y2;y2=t;w=2;/*-*/t2=0;for(i=0;i=y1)a2t2=a1i;b2t2+=b1i;if(b1i-y1)*(b1i+1-y1)=y1)a2t2=a1t1;b2t2+=b1t1;if(b1t1-y1)*(b10-y1)0)b2t2=y1;a2t2=(b1t1-y1)*(a10-a1t1)/(b1t1-b10)+a1t1;t2+;t1=0; t2-;for(i=0;i=x1)a1t1=a2i;b1t1+=b2i;if(a2i-x

11、1)*(a2i+1-x1)=x1)a1t1=a2t2;b1t1+=b2t2;if(a2t2-x1)*(a20-x1)0)a1t1=x1;b1t1=(x1-a2t2)*(b20-b2t2)/(a20-a2t2)+b2t2;t1+;t2=0;t1-;for(i=0;it1;i+)if(b1i=y2)a2t2=a1i;b2t2+=b1i;if(b1i-y2)*(b1i+1-y2)0)b2t2=y2;a2t2=(b1i-y2)*(a1i+1-a1i)/(b1i-b1i+1)+a1i;t2+;if(b1t1=y2)a2t2=a1t1;b2t2+=b1t1;if(b1t2-y2)*(b10-y2)0)b2

12、t2=y2;a2t2=(b1t1-y2)*(a10-a1t1)/(b1t1-b10)+a1t1;t2+;t1=0;t2-;for(i=0;it2;i+)if(a2i=x2)a1t1=a2i;b1t1+=b2i;if(a2i-x2)*(a2i+1-x2)0)a1t1=x2;b1t1=(a2i+1-x2)*(b2i-b2i+1)/(a2i+1-a2i)+b2i+1;t1+;if(a2t2=x2)a1t1=a2t2;b1t1+=b2t2;if(a2t2-x2)*(a20-x2)0)a1t1=x2;b1t1=(a20-x2)*(b2t2-b20)/(a20-a2t2)+b20;t1+;t1-;for(

13、i=1;i170&x5&x65&x260&x340&x400) _write(Draw doubianxing to be cut);_cut();int Bezer()num=1;while(1)GetMouseXY(&x,&y);if(oldx!=x|oldy!=y)if(y43&y460)_write(Quit: R_button);if(num=1)a0=x;b0=y;else if(num4)line(a0,b0,a1,b1);a0=a1; b0=b1;a1=a2; b1=b2;a2=a3; b2=b3;a3=x; b3=y;line(a2,b2,a3,b3);_Bezer(a,b,

14、4);num+;while(outreg.x.bx=1)GetMouseXY(&x,&y);if(outreg.x.bx=2)line(a0,b0,a1,b1);line(a1,b1,a2,b2);line(a2,b2,a3,b3);_write(welcome to use my system);return 0;void _mytreat(int oldx,int oldy,int x,int y)if(num=1)if(flag=LINE)line(px,py,oldx,oldy);line(px,py,x,y);if(flag=CIRCLE)mycircle(px,py,sqrt(do

15、uble)(px-oldx)*(px-oldx)+(py-oldy)*(py-oldy);mycircle(px,py,sqrt(double)(px-x)*(px-x)+(py-y)*(py-y);if(flag=RECTANGLE)rectangle(px,py,oldx,oldy);rectangle(px,py,x,y);void mytreat(int x,int y)if(num=0)px=x;py=y;num=1;elsenum=0;void opengraph()int gdriver,gmode;gdriver=DETECT;initgraph(&gdriver,&gmode

16、,);void _write(char *str)setcolor(15);outtextxy(200,468,string);setcolor(8);strcpy(string,str);outtextxy(200,468,string);int main()flag=num=0;opengraph();drawwindows();DisplayMouse();setwritemode(1);strcpy(string,welcome to use my system);outtextxy(200,468,string);GetMouseXY(&oldx,&oldy);mycross(oldx,oldy);while(1)GetMouseXY(&x,&y);if(oldx!=x|oldy!=y)if(y460)mycross(oldx,oldy);mycross(x,y);_mytreat(oldx,oldy,x,y);oldx=x;oldy=y;if(outreg.x.bx=1)if(y20)handlevent(&flag,x);else if(x610&x43&y460)mytreat(x,y);while(outreg.x.bx=1)GetMouseXY(&x,&y);closegraph();专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁