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

rpi-led-matrix-painter

v1.3.0

Published

Add drawing facilities to rpi-led-matrix. Manage sections of the board independently, draw shapes, text, and images.

Downloads

10

Readme

Build

About rpi-led-matrix-painter

Add drawing facilities to the excellent alexeden/rpi-led-matrix. Takes a declarative approach to drawing on the matrix. Manage sections of the board independently, draw shapes, text, images, and some simple effects.

Example

Check out wesleytabaka/rpi-led-matrix-painter-example for a working example of the library. View on YouTube

Installation

Install with npm using:

npm i rpi-led-matrix-painter --save

API Overview

Import into your app using:

import * as Board from "rpi-led-matrix-painter";

"Board" will contain the following TS modules:

  • Painter (Class)
    • This is the main class that controls drawing the PaintingInstructions and driving Effects. You'll have one instance of Painter that you'll need to access to do everything.
  • Canvas (Class)
    • Represents the entire LED matrix and consists of one or more CanvasSections that you define.
  • CanvasSection (Class)
    • A section of the board defined by x, y, width, height, and layer.
  • DrawMode (Enum)
    • Use in your PaintingInstruction to switch DrawModes. e.g., CIRCLE, RECTANGLE, POLYGON, TEXT, etc.
  • DrawModeOption (Interface)
    • Interface with properties fill?: boolean, font?: string, fontPath?: string, effects?: Effect[]
  • Effect (Interface)
    • Interface with properties effectType: EffectType, effectOptions: EffectOptions
  • EffectOptions (Interface)
    • Consists of the "rate" property for the speed of the effect.
  • EffectType (Enum)
    • One of: SCROLLLEFT, SCROLLRIGHT, SCROLLUP, SCROLLDOWN, BLINK, PULSE. Others are defined but not implemented.
  • PaintingInstruction (Interface)
    • List of properties defining what to draw and how to draw it.
  • Point (Interface)
    • Defines a point on the CanvasSection relative to the CanvasSection.
  • RpiLedMatrix (Module -- re-export of wesleytabaka/rpi-led-matrix which itself is forked off of alexeden/rpi-led-matrix)

API Detail

Here is the public API. To get started, create a new Painter instance:

import * as Board from "rpi-led-matrix-painter";

export class MyClass {

    private mypainter = new Board.Painter(
        {
            ...Board.RpiLedMatrix.LedMatrix.defaultMatrixOptions(),
            rows: 32, // LED rows per panel
            cols: 64, // LED columns per panel
            chainLength: 2 // Number of panels chained together
        },
        {
            ...Board.RpiLedMatrix.LedMatrix.defaultRuntimeOptions()
        }
    );
}

To create a CanvasSection the full size of both panels, assuming they're laid out next to each other horizontally...

this.mypainter.getCanvas().addCanvasSection(new Board.CanvasSection("mycanvassection", 0, 0, 1, 128, 32, [], true));

To set the new CanvasSection, mycanvassection to read something like "Hello, world!"...

this.mypainter.getCanvas().getCanvasSection("mycanvassection")?.setRepresentation([
    {
        id: "helloworld",
        drawMode: Board.DrawMode.TEXT,
        color: 0x800000,
        drawModeOptions: {font: "5x7", fontPath: "/home/pi/code/rpi-led-matrix-painter-test/fonts/5x7.bdf"},
        points: {x: 0, y:0, z: 1},
        text: "Hello, world!",
        layer: 1
    }
]);

The CanvasSection.setRepresentation() method takes an array of PaintingInstruction. The format of this can vary depending on the drawMode. For example, when using a DrawMode of LINE, the "points" property should be an array of Point. When using a DrawMode of TEXT, the "points" property should be one Point. The properties "id", "drawMode", and "color" are all required all of the time. When you're ready to draw to the Canvas, call paint() on the Painter object...

this.mypainter.paint();

That's it! Below is the public API spec.

Painter (Class)

  • constructor(matrixOptions: Board.RpiLedMatrix.MatrixOptions, runtimeOptions: Board.RpiLedMatrix.RuntimeOptions)
  • resetClock(): void
  • clear(): void
  • getCanvas(): Canvas
  • getFontInstance(name: string, path: string): Board.RpiLedMatrix.FontInstance
  • getImageInstance(imagePath: string): Promise<Image>
  • paint(): void

Canvas (Class)

  • constructor(matrixOptions: matrix.MatrixOptions, runtimeOptions: matrix.RuntimeOptions)
  • getCanvasSections(): CanvasSection[]
  • getCanvasSection(name: string): CanvasSection | undefined
  • setCanvasSection(name: string, paintingInstructions: PaintingInstruction[]): void
  • addCanvasSection(canvasSection: CanvasSection): void
  • removeCanvasSection(canvasSectionName: string): void
  • setCanvas(canvasSections: CanvasSectionSettings[]): void

CanvasSection (Class)

  • constructor(name: string, x: number, y: number, z: number, width: number, height: number, representation?: PaintingInstruction[], overflow?: boolean)
  • get(): CanvasSection
  • setRepresentation(paintingInstructions: PaintingInstruction[]): void

DrawMode (Enum)

  • POLYGON
    • PaintingInstruction.points: Point[]
  • RECTANGLE
    • PaintingInstruction.points: Point
  • CIRCLE
    • PaintingInstruction.points: Point
  • ELLIPSE
    • PaintingInstruction.points: Point
  • PIXEL
    • PaintingInstruction.points: Point[]
  • TEXT
    • PaintingInstruction.points: Point
  • IMAGE
    • PaintingInstruction.points: Point
  • BUFFER
    • PaintingInstruction.points: Point
  • LINE
    • PaintingInstruction.points: Point[]

DrawModeOption (Interface)

interface DrawModeOption {
    fill?: boolean,
    font?: string,
    fontPath?: string,
    effects?: Effect[]
}

Effect (Interface)

interface Effect {
    effectType: EffectType
    effectOptions: EffectOptions;
}

EffectOptions (Interface)

interface EffectOptions {
    rate: number // Expresses pixels per repaint.
}

EffectType (Enum)

  • BLINK
  • PULSE
  • FADETOBLACK
  • FADEUP
  • ROTATECLOCKWISE
  • ROTATEANTICLOCKWISE
  • SCROLLLEFT
  • SCROLLRIGHT
  • SCROLLUP
  • SCROLLDOWN

PaintingInstruction (Interface)

interface PaintingInstruction {
    id: string,
    drawMode: DrawMode,
    points: Point | Point[],
    color: number,
    layer: number,
    drawModeOptions?: DrawModeOption,
    width?: number,
    height?: number,
    text?: string,
    imagePath?: string,
    buffer?: Buffer
}

Point (Interface)

interface Point {
    x: number,
    y: number,
    z: number
}

RpiLedMatrix (Module)

This is a re-export of wesleytabaka/rpi-led-matrix which is forked off of alexeden/rpi-led-matrix. My fork just adds the filled shapes functionality.

Issues and Contributing

For bugs or feature requests create an issue and tag it accordingly.

To contribute, fork and create a Pull Request.