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

simple-pixel-grid

v1.0.6

Published

A lightweight pixel grid using canvas

Downloads

3

Readme

Simple Pixel Grid

A lightweight (2.6kb) pixel grid using canvas

See the demo here!

Installation

With npm

npm install simple-pixel-grid

With wget

wget https://framagit.org/roipoussiere/simple-pixel-grid/raw/master/dist/pixelGrid.min.js

Quick start

To run the provided example:

npm start

Then go to http://127.0.0.1/8008 (if this port is already used, you can define an other with npm config set simple-pixel-grid:port <port>)

You should see your pixel grid, that you can draw on it (and erase pixels with right-click):

Usage

Initialization: let's suppose that you created a new canvas with id 'pixelGrid'

var pixelGrid = new PixelGrid(document.getElementById('pixelGrid'), 10, 10);
pixelGrid.init();

Draw two pixels, the erase the first one.

pixelGrid.drawPixel({x: 2, y: 4});
pixelGrid.drawPixel({x: 3, y: 4});
pixelGrid.clearPixel({x: 2, y: 4});

You can get a pixel object ({x, y}) according to a position on the canvas.

var pixel = this.pixelGrid.getPixelPos(20, 20);

This is particulary usefull to draw on the pixel grid with the cursor (see example).

Reference

PixelGrid(canvas, width, height, color, borderColor, borderSize)

Create a new PixelGrid object.

  • canvas: the canvas DOM element;
  • width: the initial pixel grid width, in pixels;
  • height: the initial pixel grid height, in pixels;
  • color: the initial pixels colors (default to #808080);
  • borderColor: the initial border color (default to #404040);
  • borderSize: the initial border size (default to 1).

init()

Actually draw the pixel grid.

setPixelColor(color)

Set a new pixel color

  • color: the pixel color (default to #808080).

setGridWidth(width)

Set grid width

  • width: the new grid width, in pixels.

setGridHeight(height)

Set grid height

  • height: the new grid height, in pixels.

setGridSize(width, height)

Set grid width and height

  • width: the new grid width, in pixels;
  • height: the new grid height, in pixels.

drawPixel(pixel)

Draw a pixel at the given position.

  • pixel: a pixel object, as the form {x: <position on x axis>, y: <position on y axis>}.

clearPixel(pixel)

Erase a pixel at the given position.

  • pixel: a pixel object, as the form {x: <position on x axis>, y: <position on y axis>}.

getPixelPos(clientX, clientY)

Get the pixel position according to a position on the canvas. This is particulary usefull to draw on the pixel grid with the cursor (see example).

  • clientX: a position on the canvas on x axis, in (real) pixels;
  • clientY: a position on the canvas on y axis, in (real) pixels;
  • returns: a pixel object, as the form {x: <grid pixel on x axis>, y: <grid pixel on y axis>}.