Neat Paraskavedekatriaphobia's Meaning
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

flood-scan

0.0.1 • Public • Published

flood-scan

Marks out disconnected "rooms" in a 2D ndarray for procedural map generation.

Installation

npm install flood-scan

Usage

require('flood-scan')(ndarray[, options])

Performs a scan on the supplied array. This will fill all "empty" cells with a number for each enclosed space. By default, this will replace all zeros with numbers 2 and above. This behavior can be changed by passing in the following options:

  • limit: The maximum amount of rooms to mark. Defaults to infinity.
  • indexer: A function which takes the room number and returns the value that its cells should be filled with. Defaults to n + 2.
  • empty: A function which takes the value of a cell, and returns whether it should be considered empty. By default, only zero is considered empty.

This will return an array of objects (one for each room). Each have the following properties, most of which are borrowed from flood-fill:

  • hi: the highest x/y positions filled.
  • lo: the lowest x/y positions filled.
  • area: the total amount of cells filled in this room.
  • start: the first cell that was filled in this room.

See eyeball.js for a visual test, and a full usage example.

flood-scan example

Keywords

none

install

npm i flood-scan

Downloadsweekly downloads

4

version

0.0.1

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability