# flood-fill

> A simple 2D flood fill for use with ndarrays

Latest version **0.1.1** (published 2013-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install flood-fill
pnpm add flood-fill
yarn add flood-fill
bun add flood-fill
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2013-06-29 |
| First published | 2013-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Hugh Kennedy |
| Maintainers | hughsk |
| Keywords | flood, fill, paint, bucket, area, grid, ndarray |

## Links

- npm: https://www.npmjs.com/package/flood-fill
- Repository: https://github.com/hughsk/flood-fill
- npm.io page: https://npm.io/package/flood-fill

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2013-06-29
- 0.1.0 — 2013-06-28
- 0.0.0 — 2013-06-28

## README

# flood-fill #

A simple 2D [flood fill](http://en.wikipedia.org/wiki/Flood_fill) for use with
[ndarrays](http://github.com/mikolalysenko/ndarray).

You could use this to re-implement Microsoft Paint's bucket fill in
JavaScript, or in procedural dungeon generation to identify disconnected rooms.

[![flood fill](https://raw.github.com/hughsk/flood-fill/master/example.gif)](http://en.wikipedia.org/wiki/File:Recursive_Flood_Fill_4_%28aka%29.gif)

## Installation ##

``` bash
npm install flood-fill
```

## Usage ##

### `require('flood-fill')(ndarray, x, y, fillValue)` ###

Fills the array with `fillValue`, starting from the position at `(x, y)`.

This will also return an object with some very basic metrics for you to use:

* `area`: the total amount of cells filled.
* `hi`: the highest x/y positions filled.
* `lo`: the lowest x/y positions filled.

Note that `hi` and `lo` may not have been filled themselves.

``` javascript
var fill = require('flood-fill')
var zero = require('zeros')

var grid = zero([50, 50])
var height = grid.shape[1]
var width = grid.shape[0]

for (var x = 0; x < 50; x += 1) grid.set(x, 10, 1)
for (var x = 0; x < 50; x += 1) grid.set(x, 21, 1)
for (var y = 0; y < 50; y += 1) grid.set(10, y, 1)
for (var y = 0; y < 50; y += 1) grid.set(22, y, 1)

fill(grid, 30, 19, 2)

for (var y = 0; y < height; y += 1) {
  for (var x = 0; x < width; x += 1) {
    process.stdout.write(grid.get(x, y) ? '#' : ' ')
  }
  console.log()
}
```

---
_Source: https://npm.io/package/flood-fill · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
