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

pixels-matrix

v1.0.13

Published

PixelMatrix and Color management utility for 2D graphics and LED matrix handling.

Downloads

26

Readme

Pixels Matrix

Overview

This Lib provides utility to manage 2D pixels matrices, specifically focusing on pixel and color data manipulations, ideal for LED matrix handling.

Installation

Install via NPM:

npm install --save pixels-matrix

Key Features

  • Pixel Management: Handle pixel data in a 2D matrix.
  • Color Handling: Manage colors using different formats (RGB, HEX, and HSV).
  • Flexible Configurations: Adapt matrix rendering through customizable options.

Basic Usage

Pixel Matrix

import { PixelMatrix, Point, Color } from "pixels-matrix";

// Initialize PixelMatrix
const matrix = new PixelMatrix(8, 8);

// Set a pixel color using Point and Color
const point: Point = { x: 2, y: 3 };
const color: Color = Color.FromHEX("#ff5733");
matrix.setColor(point, color);

// Get a pixel color
const retrievedColor: Color = matrix.getColor(point);

// Fill the entire matrix with a color
matrix.fillColor(Color.Blue);

// Convert PixelMatrix data to array
const pixelArray: Uint32Array = matrix.ToArray();

Color Handling

import { Color } from "pixels-matrix";

// Create color using various formats
const colorFromRGB = Color.FromRGB(255, 87, 34);
const colorFromHEX = Color.FromHEX("#FF5722");
const colorFromHSV = Color.FromHSV(0.05, 0.66, 1);

// Retrieve uint32 data from color
const uint32Color = colorFromRGB.getUint32();
// Retrieve rgb data from color
const [r, b, g] = colorFromRGB.getRGB();

Options

MatrixOptions

MatrixOptions allows you to control the appearance of the pixel matrix.

  • x_mirrored (default false): Mirror the matrix horizontally.
  • y_mirrored (default false): Mirror the matrix vertically.
  • zigzag (default false): Enable zigzag rendering.

Example:

const options = {
  x_mirrored: true,
  y_mirrored: false,
  zigzag: true,
};
const matrix = new PixelMatrix(8, 8, options);

API Reference

Class: PixelMatrix

  • Methods:
    • getColor(point: Point): Color: Get color of the pixel at given point.
    • setColor(point: Point, color: Color): void: Set color of the pixel at given point.
    • fillColor(color: Color): void: Fill the entire matrix with a specified color.
    • getCoord(index: number): Point: Get matrix coordinates from a linear index.
    • getIndex(point: Point): number: Get linear index from matrix coordinates.
    • setMatrix(grayScale: number[][], color: Color, option?: SetMatrixOption): Apply matrix data from a 2D array.
    • ToArray(): Uint32Array: Convert matrix data to a typed array.
  • SetMatrixOption
    • xOffset (default 0): Offset of the matrix on the x-axis.
    • yOffset (default 0): Offset of the matrix on the y-axis.

Class: Color

  • Static Methods:
    • Various utility methods to create Color instances from different formats.
  • Methods:
    • getUint32(): number: Convert color to uint32 format.
    • getRGB(): [number, number, number]: Convert color to rgb format.