Draw pixel art using HTML canvas
Pixel-grid is a pixel art editor built using just JavaScript and HTML canvas. It is highly customizable and is designed to be inserted into any web application.
<canvas data-anchor="grid"></canvas>
- Include pixelGrid.js on your page.
- Define an HTML canvas element with a unique id (or data attribute if you prefer):
- Use the API below.
- Voila, start drawing Samus!
###pixelGrid.init([width][,height]) Initializes the grid
Optional Parameters: width {number of literal pixels}, height {number of literal pixels}. If no arguments are passed in, the grid will attempt to fill in the width of the parent container and dynamically set the height based on the screen size.
Clears any drawing on the grid leaving only the grid.
Resizes the width of the grid based on the input parameter.
Required Parameter: width {number of literal pixels}.
Resizes the height of the grid based on the input parameter.
Required Parameter: height {number of literal pixels}.
Draws in a pixel at a specific (x, y) coordinate.
Required Parameters: x {number in scaled pixels}, y {number in scaled pixels}, color {string color code}.
Batches the pixelGrid.color() method by taking in a JSON message. See below for the allowable format.
Required Parameter: JSON {JSON}.
Sample JSON for pixelGrid.batchColor:
var zero = {
"name": "zero",
"width": "",
"height": "",
"colors": {
"black": "#000000",
"white": "#ffffff",
"darkRed": "#740000",
"red": "#aa0000",
"lightRed": "#ff0000",
"lightGrey": "#bbbbbb",
"grey": "#555555",
"lightBlue": "#55aaff",
"blue": "#0080ff",
"orange": "#ff7700",
"skin": "#ffbb80",
"yellow": "#ffff00",
"lightGreen": "#55d200",
"green": "#358300"
},
"coordinates": [
{"x": 16, "y": 0, "color": "black"},
{"x": 15, "y": 1, "color": "black"},
{"x": 16, "y": 1, "color": "black"},
{"x": 20, "y": 1, "color": "black"},
{"x": 14, "y": 2, "color": "black"},
{"x": 15, "y": 2, "color": "darkRed"},
{"x": 16, "y": 2, "color": "black"}
]
};
</p