A simple 2D flood fill for use with ndarrays
npm install flood-fill
Fills the array with
fillValue, starting from the position at
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.
lo may not have been filled themselves.
var fill = require'flood-fill'var zero = require'zeros'var grid = zero50 50var height = gridshape1var width = gridshape0for var x = 0; x < 50; x += 1 gridsetx 10 1for var x = 0; x < 50; x += 1 gridsetx 21 1for var y = 0; y < 50; y += 1 gridset10 y 1for var y = 0; y < 50; y += 1 gridset22 y 1fillgrid 30 19 2for var y = 0; y < height; y += 1for var x = 0; x < width; x += 1processstdoutwritegridgetx y ? '#' : ' 'console.log