C#,计算几何,计算机图形学(Computer Graphics)洪水填充算法(Flood Fill Algorithm)与源代码
2023-09-11 14:15:48 时间
泛洪填充算法(Flood Fill Algorithm) ,又称洪水填充算法,是在很多图形绘制软件中常用的填充算法,最熟悉不过就是 windows 自带画图软件的油漆桶功能。
using System;
using System.Collections;
using System.Collections.Generic;
namespace Legalsoft.Truffer.Algorithm
{
/// <summary>
/// 洪水填充算法
/// </summary>
public static partial class Algorithm_Gallery
{
private static void Fill_4Directions(int[,] screen, int x, int y, int prevC, int newC)
{
int M = screen.GetLength(0);
int N = screen.GetLength(1);
if (x < 0 || x >= M || y < 0 || y >= N)
{
return;
}
if (screen[x, y] != prevC)
{
return;
}
screen[x, y] = newC;
Fill_4Directions(screen, x + 1, y, prevC, newC);
Fill_4Directions(screen, x - 1, y, prevC, newC);
Fill_4Directions(screen, x, y + 1, prevC, newC);
Fill_4Directions(screen, x, y - 1, prevC, newC);
}
public static void Flood_Fill(int[,] screen, int x, int y, int newC)
{
int prevC = screen[x, y];
if (prevC == newC)
{
return;
}
Fill_4Directions(screen, x, y, prevC, newC);
}
}
}
相关文章
- 请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符
- 利用反射快速给Model实体赋值 使用 Task 简化异步编程 Guid ToString 格式知多少?(GUID 格式) Parallel Programming-实现并行操作的流水线(生产者、消费者) c# 无损高质量压缩图片代码 8种主要排序算法的C#实现 (一) 8种主要排序算法的C#实现 (二)
- C#,《数值算法:科学计算的艺术,Numerical Recipes: The Art of Scientific Computing》
- C#,图论与图算法,计算无向连通图中长度为n环的算法与源代码
- C#,数值计算,求平方根之巴比伦算法(Babylonian algorithm)的源代码
- C#,码海拾贝(19)——一般实矩阵的QR分解(QR Decomposition)方法之C#源代码,《C#数值计算算法编程》源代码升级改进版
- C#,码海拾贝(18)——矩阵的(一般)三角分解法(Triangular Decomposition)之C#源代码,《C#数值计算算法编程》源代码升级改进版
- C#,码海拾贝(13)——矩阵及其基本计算类Matrix的源代码,《C#数值计算算法编程》源代码升级改进版
- C#,码海拾贝(11)——拉格朗日(Lagrange)三点式曲面插值算法,《C#数值计算算法编程》源代码升级改进版
- C#,码海拾贝(08)——埃特金(Aitken)逐步曲线插值算法,《C#数值计算算法编程》源代码升级改进版
- C#,码海拾贝(03)——积分Integral算法类,《C#数值计算算法编程》源代码升级改进版
- C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,对角和带对角方程组(Tridiagonal and Band-Diagonal)求解算法源程序
- C# 坦克游戏大战中学习相关类(Closing与Closed区别)
- 基于C#+MySQL实现(WinForm)旅行记录本软件【100010443】