C语言实现的扫描线种子填充算法

该程序演示了使用C语言实现的扫描线种子填充算法。用户输入多边形顶点,程序绘制边并进行区域填充。尽管还有改进空间,如颜色值的变量表示和功能模块化,但已能完成基本的填充效果。
摘要由CSDN通过智能技术生成

/***************************************************************
本程序实现区域填充功能,首先输入多边形顶点的个数,回车,
然后依次输入各顶点的坐标格式如下:100,123回车
一定要在中间用逗号隔开噢,输完最后一个点后,屏幕上会依次
画出各条边,最后填充满.
程序还不完善,比如颜色值应该用变量表示以易于修改,画多边形和求种子点
应该做成独立的函数等等,以后再做上吧,这是细节的问题
作者:曹欣
学号:2003378314
班级:计应0301
******************************************************************/

#include  < graphics.h >
#include 
< stdio.h >
#include 
< alloc.h >
#include 
< dos.h >
#include 
< conio.h >
// creat a stack
struct stack_node
{
     
int  x;
     
int  y;
     struct stack_node 
* next;
};
typedef stack_node stack_list;
typedef stack_list 
* link;
link stack 
=   0 ;

// push an element
void  push( int  xx, int  yy)
{
     link new_node;
     new_node
= (stack_list  * )malloc(sizeof(stack_list));
     new_node
-> x = xx;
     new_node
-> y = yy;
     new_node
-> next = stack;
     stack
= new_node;
}

// pop an element
void  pop( int   & xx, int   & yy)
{
     link top;
     top
= stack;
     xx
= stack -> x;
     yy
= stack -> y;
     stack
= stack -> next;
     free(top);
}


// fill the plot
void  fill( int  x, int  y)
{
     
int  x0,y0,xl,xr,xlold,xrold; /* x0,y0用来标记x,y的值,xl记录x的最左值,xr记录x的最右值 */
     
int  go = 0 ,go2 = 0 ;
     
int  i = 0 ;
     push(x,y);
// 种子像素入栈
      while (stack != 0 ) // 如果
  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值