All Projects → azsdaja → FloodSpill-CSharp

azsdaja / FloodSpill-CSharp

Licence: MIT license
A flood fill algorithm implementation for C#

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to FloodSpill-CSharp

Rotten Soup
A roguelike built with Vue, Vuetify, Tiled, rot.js, and PixiJS! Playable at https://rottensoup.herokuapp.com/
Stars: ✭ 249 (+322.03%)
Mutual labels:  roguelike
roguelike tutorial
RoguelikeDev Tutorial 2018
Stars: ✭ 33 (-44.07%)
Mutual labels:  roguelike
tektosyne
The Tektosyne Library for Java provides algorithms for computational geometry and graph-based pathfinding, along with supporting mathematical utilities and specialized collections.
Stars: ✭ 52 (-11.86%)
Mutual labels:  flood-fill
FirstAgeAngband
FAangband remade from Angband version 4
Stars: ✭ 15 (-74.58%)
Mutual labels:  roguelike
Landlord
Landlord was a planned roguelike game, which may yet be completed one day if I decide I am willing to re-approach it.
Stars: ✭ 40 (-32.2%)
Mutual labels:  roguelike
thelegendofericc
Single player roguelike tile-based game written in Java using LibGDX and Ashley
Stars: ✭ 22 (-62.71%)
Mutual labels:  roguelike
Rotlove
Roguelike Toolkit in Love. A Love2D/lua port of rot.js
Stars: ✭ 189 (+220.34%)
Mutual labels:  roguelike
Axes-Armour-Ale
A fantasy, ASCII dungeon crawler for Windows, Linux & OSX
Stars: ✭ 22 (-62.71%)
Mutual labels:  roguelike
cavernos
Retro fantasy terminal for building DOS-era ASCII games, powered by WebAssembly
Stars: ✭ 32 (-45.76%)
Mutual labels:  roguelike
yiufcrawl
Unofficial preservationist fork of DCSS
Stars: ✭ 13 (-77.97%)
Mutual labels:  roguelike
brogue-android-port
Brogue Android Port
Stars: ✭ 47 (-20.34%)
Mutual labels:  roguelike
rogue.js
JavaScript porting of original Rogue source code using Emscripten
Stars: ✭ 33 (-44.07%)
Mutual labels:  roguelike
wglt
WebGL Terminal
Stars: ✭ 43 (-27.12%)
Mutual labels:  roguelike
Burningknight
C# branch of BK
Stars: ✭ 251 (+325.42%)
Mutual labels:  roguelike
Rogue-Collection
Retro Rogue Collection: Six versions of the classic Rogue game with customizable retro graphics. Now with Rogomatic support!
Stars: ✭ 75 (+27.12%)
Mutual labels:  roguelike
Ivan
Iter Vehemens ad Necem - a continuation of the graphical roguelike by members of http://attnam.com
Stars: ✭ 219 (+271.19%)
Mutual labels:  roguelike
runeHunter
A coffee break roguelike game written in JS. Explore the dungeon, collect 3 runes and escape alive.
Stars: ✭ 25 (-57.63%)
Mutual labels:  roguelike
FAangband
First Age Angband
Stars: ✭ 57 (-3.39%)
Mutual labels:  roguelike
LightMask
A tiny 2D header-only flood-fill lighting engine
Stars: ✭ 71 (+20.34%)
Mutual labels:  roguelike
goldfish
Goldfish: a game created for the 7-day Roguelike 2017 challenge. Playable, winnable, losable. Features colorful and aesthetic maps, aquatic fauna and fishermen!
Stars: ✭ 28 (-52.54%)
Mutual labels:  roguelike

logo

FloodSpill — a free multi-purpose flood-fill algorithm for C#

What can you do with it?

  • run a flood-fill in two-dimensional space,
  • pass your own conditions for visiting positions and for stopping the flood,
  • pass your own callbacks that will be executed for visited positions,
  • use LIFO, FIFO or priority queue for deciding in what order positions should be visited,
  • decide if you allow diagonal neighbourhood of positions or not,
  • use scanline fill to double up execution speed.

It is:

  • fast and memory efficient,
  • easy to use,
  • elastic,
  • compatible with .NET Standard 1.6+ and .NET Framework 3.5+.

It can for example be used in games (roguelikes, RTS, RPG) to calculate so called influence maps, scent maps, Dijkstra maps et cætera.


Usage example

var wallMatrix = new bool[6, 5]; // setting up some obstacles for flood
wallMatrix[2, 0] = wallMatrix[2, 1] = wallMatrix[2, 2] 
	= wallMatrix[3, 0] = wallMatrix[3, 1] = wallMatrix[3, 2] = true;

Predicate<int, int> positionQualifier = (x, y) => wallMatrix[x, y] == false;

var floodParameters = new FloodParameters(startX: 0, startY: 0)
{
	Qualifier = positionQualifier
};
var markMatrix = new int[6, 5];

new FloodSpiller().SpillFlood(floodParameters, markMatrix);

Code above fills markMatrix with numbers indicating in how many steps the starting position is reachable:

presentation


More advanced example

private int[,] _positionMarkMatrix;

public void BucketFillImage(int floodStartX, int floodStartY, Color replacedColor, Color targetColor)
{
	var floodSpiller = new FloodSpiller();
	var floodParameters = new FloodParameters(floodStartX, floodStartY)
	{
		BoundsRestriction = new FloodBounds(_imageSizeX, _imageSizeY),
		NeighbourhoodType = NeighbourhoodType.Four,
		Qualifier = (x, y) => GetColor(x, y) == replacedColor,
		NeighbourProcessor = (x, y, mark) => SetColor(x, y, targetColor),
		ProcessStartAsFirstNeighbour = true
	};

	floodSpiller.SpillFlood(floodParameters, _positionMarkMatrix);
}

For more instructions and code examples see Getting started section in wiki.


Performance report measured with BenchmarkDotNet

(with checking for wall presence by accessing a bool[,] matrix; measured on a good 2016 laptop with Intel i7-6700HQ)

Area size Walls blocking flood Mode Mean execution time Allocated memory
20x20 No walls (open area) Normal 33 µs < 1kB
20x20 No walls (open area) Scanline 15 µs < 1kB
20x20 Sparse pillars (11% of area) Normal 33 µs < 1kB
20x20 Sparse pillars (11% of area) Scanline 23 µs < 1kB
20x20 Circular walls (50% of area) Normal 20 µs < 1kB
20x20 Circular walls (50% of area) Scanline 10 µs < 1kB
200x200 No walls (open area) Normal 3,458 µs 16 kB
200x200 No walls (open area) Scanline 1,158 µs < 1kB
200x200 Sparse pillars (11% of area) Normal 3,072 µs 16 kB
200x200 Sparse pillars (11% of area) Scanline 2,430 µs 8 kB
200x200 Circular walls (50% of area) Normal 2,031 µs 8 kB
200x200 Circular walls (50% of area) Scanline 879 µs < 1kB
2000x2000 No walls (open area) Normal 371,000 µs 131 kB
2000x2000 No walls (open area) Scanline 117,000 µs < 1kB
2000x2000 Sparse pillars (11% of area) Normal 328,000 µs 131 kB
2000x2000 Sparse pillars (11% of area) Scanline 262,670 µs 66 kB
2000x2000 Circular walls (50% of area) Normal 216,312 µs 66 kB
2000x2000 Circular walls (50% of area) Scanline 88,618 µs 8 kB
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].