计算机图形学实验区域填充算法的实现.docx

计算机图形学实验区域填充算法的实现.docx

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验三 区域填充算法的实现班级 10信计2班 学号 姓名 一、实验目的和要求:1、掌握区域填充算法基本知识2、理解区域的表示和类型,能正确区分四连通和八连通的区域3、了解区域填充的实现原理,利用Microsoft Visual C++ 6.0或win-TC实现区域种子填充的递归算法。二、实验内容:1、编程完成区域填色2、利用画线函数,在屏幕上定义一个封闭区域。3、利用以下两种种子填充算法,填充上述步骤中定义的区域边界表示的四连通区域种子填充的实现内点表示的四连通区域种子填充的实现4、将上述算法作部分改动应用于八连通区域,构成八连通区域种子填充算法,并编程实现。 三、实验结果分析四连通图的实现:程序代码:#includegraphics.h#include conio.h#includemath.h#includetime.hvoid BoundaryFill4(int x,int y,int Boundarycolor,int newcolor){if(getpixel(x,y) != newcolor getpixel(x,y) !=Boundarycolor){putpixel(x,y,newcolor);Sleep(1);BoundaryFill4(x-1,y,Boundarycolor,newcolor);BoundaryFill4(x,y+1,Boundarycolor,newcolor);BoundaryFill4(x+1,y,Boundarycolor,newcolor);BoundaryFill4(x,y-1,Boundarycolor,newcolor);}}void polygon(int x0,int y0,int a,int n,float af){int x,y,i;double dtheta,theta;if(n3)return;dtheta=6.28318/n;theta=af*0.0174533;moveto(x0,y0);x=x0;y=y0;for(i=1;in;i++){x=x+a*cos(theta);y=y+a*sin(theta);lineto(x,y);theta=theta+dtheta;}lineto(x0,y0);}void main(){ int x=50,y=75;int a,b,c,d,i,j;int graphdriver=DETECT;int graphmode=0;initgraph(graphdriver,graphmode, );cleardevice();setcolor(RGB(0,255,0));setfillstyle(WHITE);polygon(x,y,60,5,0.);a=100;b=100;c=RGB(0,255,0);d=RGB(255,0,255);BoundaryFill4(a,b,c,d);getch();closegraph();}实验结果 八连通的实现程序代码:#includegraphics.h#includeconio.h#includetime.h#include malloc.h#include windows.h#define MaxSize 100typedef struct{ int x; int y;}Seed,ElemType;typedef struct {ElemType data[MaxSize];int top;//栈顶指针} SqStack;void InitStack(SqStack *s){s=(SqStack *)malloc(sizeof(SqStack));s-top=-1;}int StackEmpty(SqStack *s){return(s-top==-1);}int Push(SqStack *s,ElemType e){if (s-top==MaxSize-1)return 0;s-top++;s-data[s-top]=e;return 1;}int Pop(SqStack *s,ElemType e){if (s-top==-1)return 0;e=s-data[s-top];s-top--;return 1;}void floodfill8(int x,int y,int oldcolor,int newcolor){ if(getpixel(x,y)==oldcolor) { putpixel(x,y,newcolor); Sleep(2); floodfill8(x,y+1,oldcolor,newcolor); floodfill8(x,y-1,oldcolor,newcolor); floodfill8(x-1,y,oldcolor,newcolor); flood

文档评论(0)

gangshou + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档