🚀 DAY 2 OF LAUNCH WEEK: Announcing Socket Certified Patches: One-Click Fixes for Vulnerable Dependencies.Learn more →
Socket
Book a DemoInstallSign in
Socket

@darkaqua/flood-fill

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@darkaqua/flood-fill

A simple 2D [flood fill](http://en.wikipedia.org/wiki/Flood_fill) with no stupid dependencies!

latest
npmnpm
Version
1.0.0
Version published
Maintainers
2
Created
Source

flood-fill

A simple 2D flood fill with no stupid dependencies!

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

Usage

import { getGrid } from './mod.ts';

const grid = createGrid(50, 50);

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

const result = grid.floodFill(30, 19);

let output = "";

for (let y = 0; y < grid.height; y++) {
    for (let x = 0; x < grid.width; x++) {
        const cell = grid.cells[y * grid.width + x];
        const filledCell = result.filledGrid.cells[y * grid.width + x];
        
        output += cell !== 0 ? "#" : filledCell !== 0 ? "@" : " ";
    }
    
    if (y < grid.height - 1) {
        output += "\n";
    }
}

console.log(output);

FAQs

Package last updated on 17 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts