计算机图形学区域填充算法win tc,计算机图形学实验区域填充算法的实现(8页)-原创力文档...

实验三 区域填充算法的实现

班级10信计2班 学号姓名

一、实验目的和要求:

1、掌握区域填充算法基本知识

2、理解区域的表示和类型,能正确区分四连通和八连通的区域

3、了解区域填充的实现原理,利用Microsoft Visual C++ 6.0或win-TC实现区 域种子填充的递归算法。

二、实验内容:

1、编程完成区域填色

2、利用画线函数,在屏幕上定义一个封闭区域。

3、利用以下两种种子填充算法,填充上述步骤中定义的区域

边界表示的四连通区域种子填充的实现

内点表示的四连通区域种子填充的实现

4、将上述算法作部分改动应用于八连通区域,构成八连通区域种子填充算法, 并编程实现。

三、实验结果分析

四连通图的实现:

程序代码:

#includeh>

#include

# include

#include

void BoundaryFill4(int x,int yjnt Boundarycolor^int newcolor)

{

if(getpixel(x,y) != newcolor && getpixel(x,y) !=Boundarycolor)

{

putpixel(x^newcolor);

Sleep(l);

BoundaryFin4(x-l9y,Boundarycolor,newcolor);

BoundaryFill4(x,y+l,Boundarycolor,newcolor);

BoundaryFill4(x+l^Boundarycolor,newcolor); BoundaryFill4(x,y-l,BoundarycoIor^newcolor);

}

}

void polygon(int xOJnt yO^int a,int n^float af)

int x,y,i;

double dtheta,theta;

if(n<3)

return;

dtheta=6.28318/n; theta=af*0.0174533; moveto(xO,yO);x=xO;y=yO;

for(i=l;i

{

x=x+a*cos(theta);y=y+a*sin(theta); lineto(x,y);theta=theta+dtheta;

}

Iineto(x0,y0);

}

void main()

{

int x=50,y=75;

int a,b,c,d,ij;

int graphdriver=DETECT;

int graphmode=0;

initgraph(&graphdriver,&graphmode9n "); 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();}

实验结果

■ liantong4

□—冈

八连通的实现

程序代码:

#include

#includeh>

#include

#include

#include

#define MaxSize 100

typedef struct!

int x;

inty;

}Seed,ElemType;

typedef struct

{

ElemTS pe data[MaxSize];

int top;〃栈顶指针

} SqStack;

void InitStack(SqStack *&s)

{

s=(SqStack *)malloc(sizeof(SqStack));

s->top=-l;

}

int StackEmpty(SqStack *s)

{

return(s ?> top==-l);

}

int Push(SqStack *&s,EIemType 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==-l)

return 0;

e=s->data[s->top];

s->top—;

return 1;

void floodfi!18(int x,int yjnt oldcolorjnt nevvcolor)

if(getpixel(x,y)==oldcol

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值