边界填充算法讲解_边界填充算法
边界填充算法讲解
Boundary fill is the algorithm used frequently in computer graphics to fill a desired color inside a closed polygon having the same boundary color for all of its sides.
边界填充是在计算机图形学中经常使用的算法,用于在其所有边都具有相同边界颜色的封闭多边形内填充所需颜色。
The most approached implementation of the algorithm is a stack-based recursive function.
该算法最接近的实现是基于堆栈的递归函数。
这个怎么运作: (How it works:)
The problem is pretty simple and usually follows these steps:
该问题非常简单,通常按照以下步骤操作:
- Take the position of the starting point and the boundary color.取起点的位置和边界颜色。
- Decide wether you want to go in 4 directions (N, S, W, E) or 8 directions (N, S, W, E, NW, NE, SW, SE).确定您要沿4个方向(N,S,W,E)还是8个方向(N,S,W,E,NW,NE,SW,SE)行驶。
- Choose a fill color.选择一种填充颜色。
- Travel in those directions.朝那些方向旅行。
- If the pixel you land on is not the fill color or the boundary color , replace it with the fill color.如果您着陆的像素不是填充颜色或边界颜色,则将其替换为填充颜色。
Repeat 4 and 5 until you’ve been everywhere within the boundaries.
重复4和5,直到到达边界内的任何地方。
某些限制: (Certain Restrictions:)
The boundary color should be the same for all the edges of the polygon.
多边形的所有边缘的边界颜色应相同。
The starting point should be within the polygon.
起点应在多边形内。
代码段: (Code Snippet:)
void boundary_fill(int pos_x, int pos_y, int boundary_color, int fill_color)
{
current_color= getpixel(pos_x,pos_y); //get the color of the current pixel position
if( current_color!= boundary_color || currrent_color != fill_color) // if pixel not already filled or part of the boundary then
{ putpixel(pos_x,pos_y,fill_color); //change the color for this pixel to the desired fill_colorboundary_fill(pos_x + 1, pos_y,boundary_color,fill_color); // perform same function for the east pixelboundary_fill(pos_x - 1, pos_y,boundary_color,fill_color); // perform same function for the west pixelboundary_fill(pos_x, pos_y + 1,boundary_color,fill_color); // perform same function for the north pixelboundary_fill(pos_x, pos_y - 1,boundary_color,fill_color); // perform same function for the south pixel
}
}
From the given code you can see that for any pixel that you land on, you first check whether it can be changed to the fill_color and then you do so for its neighbours till all the pixels within the boundary have been checked.
从给定的代码中可以看到,对于您着陆的任何像素,首先要检查是否可以将其更改为fill_color,然后对其相邻像素进行更改,直到检查了边界内的所有像素为止。
翻译自: https://www.freecodecamp.org/news/boundary-fill-algorithm/
边界填充算法讲解
相关文章:

使用Git管理源代码
git是个了不起但却复杂的源代码管理系统。它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作。让我们诚实一记吧:Git是复杂的,我们不要装作它不是。但我仍然会试图教会你用(我的)基本的Git和远程代…

[.Net跨平台]部署DTCMS到Jexus遇到的问题及解决思路---Linux环境搭建
最近朋友托我帮忙研究如何把一个DTCMS部署到Linux下,经过1天的研究,部署基本成功,可能有些细节还未注意到,现在把心得分享一下。过程比预期的要简单 身为.Net程序员,这个问题的第一步可能就是如何搭建一个Linux环境来测…

Sequence point 中文
摘自维基百科: In C[4] and C,[5] sequence points occur in the following places. (In C, overloaded operators act like functions, and thus operators that have been overloaded introduce sequence points in the same way as function calls.) Between ev…

python中pop函数_Python中的Pop函数
python中pop函数什么是弹出功能? (What is the pop function?) The method pop() removes and returns the last element from a list. There is an optional parameter which is the index of the element to be removed from the list. If no index is specified…

第六周学习进度条
日期 任务 听课 编程 阅读 准备考试 日总计 周日 周一 120 300 0 0 420 100 周二 0 120 0 0 120 周三 0 0 0 0 0 周四 0 0 0 0 0 周五 0 0 0 0 0 周六 0 120 100 0 …

1071. 小赌怡情(15)
常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注t个筹码后,计算机给出第二个数。若玩家猜对了,则系统奖励玩家t个筹码;…

关于年长程序员的5个误传
原文链接:http://kb.cnblogs.com/page/150932/ 英文原文:Five Pervasive Myths About Older Software Developers 最近我刚过完40岁生日,一个朋友向我开玩笑地说“嘿,你已经老了,不适合做程序员了!”我虽然…

java中getter_Java中的Getter和Setters解释了
java中getterGetters and setters are used to protect your data, particularly when creating classes. Getter和Setter用于保护数据,尤其是在创建类时。 For each instance variable, a getter method returns its value while a setter method sets or updates…

Loadrunner手动关联详解
Loadrunner手动关联详解 一、关联的含义: 关联(correlation):在脚本回放过程中,客户端发出请求,通过关联函数所定义的左右边界值(也就是关联规则),在服务器所响应的内容中…

解决Visual Studio禁止使用strlen函数的问题
问题描述: 在学习C的复制构造函数以及复制赋值运算符的重载时,需要用到使用C风格的字符串作为引入,由于我用的是VS2015(社区版),在编译时出错。编译器提醒strcpy函数是不安全的,建议改用strlen_…

求整型数组所有子串的和中的最大值
#include <iostream> using namespace std;const int MIN_INT -2147483647;int maxSum(const int *arr, int len){int my_max MIN_INT;int tmp 0;for(int i 0; i < len; i){//从头到尾。。tmp arr[i];//遍历相加。if(my_max < tmp){//更新my_maxmy_max tmp;}…

c语言中的if语句_If ... C中的其他语句解释
c语言中的if语句Conditional code flow is the ability to change the way a piece of code behaves based on certain conditions. In such situations you can use if statements.条件代码流是根据某些条件更改一段代码的行为的能力。 在这种情况下,可以使用if语句…

设计模式之笔记--装饰模式(Decorator)
装饰模式(Decorator) 定义 装饰模式(Decorator),动态地给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更为灵活。 类图 描述 Component:被装饰者和装饰者共有的基…

整型数组负数放左面,其他放右面,要求时空复杂度:O(n), O(1)。
例如:处理前:{5 -3 6 -7 -6 1 8 -4 0 0},处理后:{-3 -7 -6 -4 5 6 1 8 0 0}. #include <iostream> #include <algorithm> using namespace std;const int LEN 10; void printInt(int c){cout<<c<<"…

[bzoj] 1176 Mokia || CDQ分治
原题 给出WW的矩阵(S没有用,题目有误),给出无限次操作,每次操作的含义为: 输入1:你需要把(x,y)(第x行第y列)的格子权值增加a 输入2:你需要求出以左下角为(x1,y1),右上角为(x2,y2)的矩阵内所有格子的权值和,…

sql子查询示例_SQL更新查询示例说明
sql子查询示例In this article, were going to learn how to use the SQL update statement - what it is, what it can do, and what you need to be aware of before using it.在本文中,我们将学习如何使用SQL更新语句-它是什么,它可以做什么以及在使用…

keepalived+nginx安装
安装keepalivednginx做为公司服务器前端高可用反向代理安装nginx 1、yum install -y pcre pcre-devel gcc-c zlib zlib-devel openssl openssl-devel 2、cd /usr/local/soft 3、wget http://nginx.org/download/nginx-1.12.2.tar.gz 4、tar -zxvf nginx-1.12.2.tar.gz 5、cd ng…

Nexus Repository Manager 3.0 发布
著名仓库管理工具Nexus,在2016年4月6日发布3.0版本(包括OSS版),相较2.*版本有很大的改变: 1. 从底层重构,从而提高性能,增强扩展能力,并改善用户体验 2. 升级界面,增加更…

计算整型数的二进制中包含多少个1
方法很多啊,比如://1.靠循环: int calculate(unsigned int n){int count 0;unsigned int mark 0x1;for(int i 0; i < 32; i){if(n&mark){count;mark<<1;}}return count; }//2. 据说不用循环就能算出来的牛叉方法。木有测试。…

nvm npm不是内部命令_npm作弊表-最常见的命令和nvm
nvm npm不是内部命令npm or the Node Package Manager, is one of the most used tools for any Node.js developer. Heres a list of the most common commands youll use when working with npm.npm或Node Package Manager是Node.js开发人员最常用的工具之一。 这是使用npm时…

快速排序的实现与注意点
先上实现了的C代码: 1 #include <ctime>2 #include <cstdio>3 #include <cstdlib>4 #include <iostream>5 using namespace std;6 const int maxn 100;7 int a[maxn], n;8 void quick_sort(int left, int right) {9 if(left > …

iOS 线程之GCD的高级使用方法
之前的一篇关于线程的blog已经为大家介绍了GCD的简单使用方式及样例说明,今天因为项目中有特殊的应用GCD的实例,为大家介绍两种特殊需求的使用GCD的方法。 目的:实现一件事情做完,再做下一件事情。确保函数的运行周期。 解决方式…

构造次优查找树
似乎有些错误,但是错在哪了呢? #include <iostream> #include <cmath> using namespace std;const int NUM 9;int value[NUM] {1,2,3,4,5,6,7,8,9}; float weight[NUM] {1,1,2,5,3,4,4,3,5}; float sum_weight[NUM]; void init_sum_weigh…

同步等待 异步等待_异步/等待和承诺的解释
同步等待 异步等待The async / await operators make it easier to implement many async Promises. They also allow engineers to write clearer, more succinct, testable code.async / await 运算符使实现许多异步Promises变得更加容易。 它们还允许工程师编写更清晰&#…

使用 GDB 调试多进程程序
使用 GDB 调试多进程程序 来源 https://www.ibm.com/developerworks/cn/linux/l-cn-gdbmp/index.html GDB 是 linux 系统上常用的 c/c 调试工具,功能十分强大。对于较为复杂的系统,比如多进程系统,如何使用 GDB 调试呢?考虑下面这…

理解Lucene索引与搜索过程中的核心类
理解索引过程中的核心类 执行简单索引的时候需要用的类有: IndexWriter、Directory、Analyzer、Document、Field 1、IndexWriter IndexWriter(写索引)是索引过程的核心组件,这个类负责创建新的索引,或者打开已有的索引…

lua的table+setfenv+setmetatable陷阱
--file1.lua x funciton() print("this is x") end ------------- --file2.lua local t {} local _G _G setfenv(1,t) --设置了这个之后,只要是在本文件中对未声明变量的访问,全部会导致递归。 _G.setmetatable(t, { __index fu…

rest api_REST API
rest api历史 (History) REST stands for Representational State Transfer protocol. Roy Fielding defined REST in his PhD dissertation in 2000.REST代表再表象小号泰特贸易交接协议。 Roy Fielding在2000年的博士学位论文中定义了REST。 什么是REST API? (Wh…

0414复利计算6.0--结对
结对同伴:姓名:柯晓君学号:201406114210博客园地址:http://www.cnblogs.com/950525kxj/一、项目简介 开发工具:eclipse 开发语言:java 主要功能:复利单利的计算、贷款的计算以及投资运算三大功能…

把简单做到极致
我真的还没有认真想过我已经是一名即将毕业的大三学生了。关于自己的过去,关于自己的未来。 有时候也有想过好好反思一下自己的过去,却发现自己的过去总是被太多的无奈与遗憾填满。有时候想畅想一下自己的未来,却发现未来总是充满了未知与迷茫…