npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

binary-pixel-map

v1.2.1

Published

A library for creating and editing a binary 2D pixel map

Downloads

9

Readme

binary-pixel-map

A library written in TypeScript for creating and editing a binary 2D pixel map, made for usage with small monochrome displays, for example on a Raspberry Pi or Arduino.

This library is based on oled-js and oled-font-5x7 by noopkat.

Installation

yarn add binary-pixel-map

Usage

import { PixelMap, Pixel } from 'binary-pixel-map';

// Create a new pixel map with a width of 54, height of 18.
const map = new PixelMap(54, 18);

// Draw "Hello, world!" on the map.
map.text(1, 1, 'Hello,');
map.text(1, 10, 'world!');

// Enable the top left and bottom right pixel.
map.set(0, 0, Pixel.ON);
map.set(53, 17, Pixel.ON);

console.log(map.toString());

The example above will output the following:

PixelMap { x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
           - x - - - x - - - - - - - - - - - - x x - - - - - - x x - - - - - - - - - - - - - - - - - - - - - - - - - -
           - x - - - x - - - - - - - - - - - - - x - - - - - - - x - - - - - - - - - - - - - - - - - - - - - - - - - -
           - x - - - x - - - - x x x - - - - - - x - - - - - - - x - - - - - - x x x - - - - - - - - - - - - - - - - -
           - x x x x x - - - x - - - x - - - - - x - - - - - - - x - - - - - x - - - x - - - - - - - - - - - - - - - -
           - x - - - x - - - x x x x x - - - - - x - - - - - - - x - - - - - x - - - x - - - - x x - - - - - - - - - -
           - x - - - x - - - x - - - - - - - - - x - - - - - - - x - - - - - x - - - x - - - - - x - - - - - - - - - -
           - x - - - x - - - - x x x - - - - - x x x - - - - - x x x - - - - - x x x - - - - - x - - - - - - - - - - -
           - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
           - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
           - - - - - - - - - - - - - - - - - - - - - - - - - - x x - - - - - - - - - x - - - - - x - - - - - - - - - -
           - - - - - - - - - - - - - - - - - - - - - - - - - - - x - - - - - - - - - x - - - - - x - - - - - - - - - -
           - x - - - x - - - - x x x - - - - x - x x - - - - - - x - - - - - - x x - x - - - - - x - - - - - - - - - -
           - x - - - x - - - x - - - x - - - x x - - x - - - - - x - - - - - x - - x x - - - - - x - - - - - - - - - -
           - x - x - x - - - x - - - x - - - x - - - - - - - - - x - - - - - x - - - x - - - - - x - - - - - - - - - -
           - x - x - x - - - x - - - x - - - x - - - - - - - - - x - - - - - x - - - x - - - - - - - - - - - - - - - -
           - - x - x - - - - - x x x - - - - x - - - - - - - - x x x - - - - - x x x x - - - - - x - - - - - - - - - -
           - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - x }

API

PixelMap

new PixelMap(width: number, height: number);

get

get(x: number, y: number): PixelStatus;

Get the value of the pixel at [x, y].

getAll

getAll(): PixelStatus[][];

Get all pixels.

set

set(x: number, y: number, status: PixelStatus): void;

Set the value of the pixel at [x, y];

clear

clear(): void;

Clear the whole map.

fill

fill(status: PixelStatus): void;

Fill the map with enabled (ON) or disabled (OFF) pixels.

line

line(x0: number, y0: number, x1: number, y1: number, status: PixelStatus = Pixel.ON): void;

Draw a line from [x0, y0] to [x1, y1] using Bresenham's line algorithm.

rectangle

rectangle(x: number, y: number, width: number, height: number, outline: boolean = false, status: PixelStatus = Pixel.ON): void;

Draw a rectangle at [x, y] with the size [width, height]. If outline is set to true, only an outline will be drawn. Otherwise the rectangle will be filled.

text

text(x: number, y: number, content: string, size: number = 1, spacing: number = 2, wrap: boolean = true): void;

Draw text at [x, y] with size size. The standard size (size = 1) for letters is 5 x 7.

copy

copy(from: PixelMap, x: number = 0, y: number = 0): void;

Copy another pixel map onto the current pixel map at [x, y].

image

async image(path: string | Buffer, x: number = 0, y: number = 0, maxWidth?: number, maxHeight?: number): Promise<void>;

Copy an image onto the pixel map. path can be a file path or image buffer. Supported file types are: PNG, JPEG, WebP, GIF, SVG and TIFF.

toArray

toArray(): PixelStatus[];

Get the map as sequence of all rows. Can be useful for displaying the map on a display.

toString

toString(): string;

Get the map as string. Can be useful for debugging.

Pixel

import { Pixel } from 'binary-pixel-map';

PixelStatus

type PixelStatus = boolean;

Used as alternative to booleans. You can still use regular booleans if you prefer.

Pixel.ON

Alternative way of writing true.

Pixel.OFF

Alternative way of writing false.