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

gridpaint-ts

v6.2.2

Published

a canvas for creating grid-based art in the browser

Downloads

12

Readme

gridpaint

A canvas for creating grid-based art in the browser. gridpaint supports dynamic colour palettes and various tools such as bucket fill and undo.

examples/browser.js demonstration

Click the image above to test a demonstration!

You can build/rebuild the example locally with:

$ npm run prepack
$ npm run test-browser

Installation

$ npm install --save github:adedomin/gridpaint

examples/browser.js

For an understanding of how to use GridPaint in the canvas, see:

examples/browser.js;

It contains documentation on how to use the canvas.

examples/node.js

To be filled/updated.

server-sided rendering demonstration

^-- Example of an image made with pureimage on node.

Public properties of a GridPaint instance

All of these properties can be adjusted on the fly and will be applied next animation frame.

painter.width = 16; // painter width (in cells)
painter.height = painter.width; // painter height (in cells)
painter.cellWidth = 16; // the width of each cell
painter.cellHeight = painter.cellWidth; // the height of each cell

painter.background = true; // draw the checkered transparent background
painter.colour = 0; // the currently selected colour in a palette; is an index.
painter.cursor = { x: -1, y: -1 }; // crosshair location; more for the event handlers.
painter.grid = false; // display grid lines that visually separate individual cells.
painter.isApplied = false; // the status of mousedown
// colours the image will contain
painter.palette =  [ 'transparent', '#fff', '#c0c0c0', '#808080', '#000',
                     '#f00', '#800', '#ff0', '#808000', '#0f0', '#080', '#0ff',
                     '#008080', '#00f', '#000080', '#f0f', '#800080' ]
// 2D array: painting[row][column]. values in columns are an index into the current painter.palette.
painter.painting = [ [], ... ];
painter.tool = 'pencil'; // the currently selected tool (pencil or bucket)

// Arrays containing copies of previous instances of painter.painting.
painter.undoHistory = [];
painter.redoHistory = [];

// whether or not the draw loop is activated (activated after init() is called)
painter.drawing = true;

painter.canvas = HTMLCanvasElement; // the DOM element to append to the document

API

new GridPaint(options)

Create a new painter instance.

options is an optional object that can contain the following properties (see above property definitions for defaults):

interface GridPaintOptions {
    width?: number,
    height?: number,
    cellWidth?: number,
    cellHeight?: number,
    palette?: string[],
    outline?: boolean,
    grid?: boolean,
    colour?: number,
}

painter.action()

Apply the current tool, at the current painter.cursor, to the canvas.

Only GridPaintActionTools can be used:

type GridPaintActionTools =
    'pencil' | 'bucket' | 'line';

Usage example:

painter.setTool('pencil');
painter.cursor = { x: 1, y: 2 };
painter.action();

painter.applyTool([isApplied])

Apply (or unapply) whichever tool is selected to the canvas in the cursor's current position. This is more a conveinence for built-in Event handling code and users will likely not use or want this.

isApplied is a Boolean value. If not provided, isApplied is toggled instead.

painter.bucket([replace, x, y])

Fill in surrounding, like-coloured cells.

replace is the colour index to replace. If not provided, the colour currently set is used.

x and y are the coordinates to begin the replacement process. If not provided, cursor.x and cursor.y is used.

painter.clear([init, default_colour])

effectively delete the painting and replace every cell to a specific color.

init is used to initialize the painting, do not set or set it to false.

default_colour the color to set every cell in the painting with. The default value is 0.

painter.clearWith([colour])

This is a convenience wrapper around painter.clear which sets init to false and if colour is not given, the current painter.colour is used instead.

painter.compare()

After making changes to a painting (outside of event handlers) you can use this to detect and push changes to the history.

painter.destroy()

Remove event handlers and cease the draw loop (browser only).

painter.init()

Initialize event handlers and start the draw loop (browser only).

painter.pencil()

Set the cell in cursor's position to the selected colour.

painter.redo()

Redo the last undo action.

painter.replace(old, replace)

Replace old colour with replace colour.

Both arguments can be either the position of a colour on the palette, or a string of the colour to be indexOf'd.

painter.fitToWindow()

Adjusts the cellWidth and heights to make the canvas fit its parent element's size.

painter.resize([w, h])

Resize the painter.cellWidth to w and painter.cellHeight to h. This also resizes the html <canvas> element that gridpaint uses. This is usually not used, consider painter.fitToWindow() instead.

painter.resizePainting([w, h, default_colour])

NOT TO BE CONFUSED WITH painter.resize(). Physically grow or shrink the painter.painting. The function will attempt to center the existing content in the painting. Any new cells will be initialized with the colour of default_colour. If default_colour is not specified, 0 is used.

Notes: undo and redo may grow or shrink your painting so be careful carrying

painter.saveAs([file, scale])

Export the painting as a PNG file.

file is the default filename to save to. Default: "painting.png".

scale is a Number that describes what scale to resize the saved canvas (0.5 will be half the original, 2 would be twice as large). Default: 1.

painter.undo()

Undo the last action since the last tool was applied.